I have put a listbox item on my word document and put the following code in
VB :
Private Sub Document_Open()
ListBox1.AddItem ("item 1"), 0
ListBox1.AddItem ("item 2"), 1
ListBox1.AddItem ("item 3"), 2
ListBox1.AddItem ("item 4"), 3
End Sub
Private Sub ListBox1_Click()
If ListBox1.ListIndex = 1 Then
MsgBox ("this is item 2"), vbOKOnly
If ListBox1.ListIndex = 3 Then
MsgBox ("this is item 4"), vbOKOnly
End If
End If
End Sub
My question : this code only works when I click item 2.
what is wrong please??
Doug Robbins - 28 Apr 2005 14:01 GMT
The End If's are out of place. The correct construction is:
If ListBox1.ListIndex = 1 Then
MsgBox ("this is item 2"), vbOKOnly
End If
If ListBox1.ListIndex = 3 Then
MsgBox ("this is item 4"), vbOKOnly
End If
or
If ListBox1.ListIndex = 1 Then
MsgBox ("this is item 2"), vbOKOnly
ElseIf ListBox1.ListIndex = 3 Then
MsgBox ("this is item 4"), vbOKOnly
End If

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>
> I have put a listbox item on my word document and put the following code
[quoted text clipped - 32 lines]
>
> what is wrong please??