Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

problems using listbox.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dirk - 28 Apr 2005 07:49 GMT
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??
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.