Selecting from a List Box

B

bigbore50

Hello,

I have a list box that shows many documents names

i want to be able to select lets say 3 documents and have some code
pull up first selection and
make location1 = that document

List box
doc1.doc
doc2.doc
doc3.doc

Lets say i have doc2 and doc3 selected
i want some code to set location1 = doc2.doc
and location2 = doc3.doc

I am having problems with it so i am just scrapping my code

Do you have any ideas?

Thanks
 
R

Rob Parker

The following code will place the values of the first three selected items
from a listbox named "MyListBox" into three controls, named "Location1",
"Location2", and "Location3", on the form. The controls can be bound or
unbound, depending on what you want to do with the data. The code is in the
AfterUpdate event of the listbox, so it runs whenever the selection in the
listbox changes.

Private Sub MyListBox_AfterUpdate()
Dim i As Integer
Dim imax As Integer

' Clear the Location controls
For i = 1 To 3
Me.Controls.Item("Location" & i).Value = Null
Next i

With MyListBox
If .ItemsSelected.Count > 3 Then imax = 3 Else imax =
..ItemsSelected.Count
For i = 1 To imax
'set controls to first three selected items in the listbox
Me.Controls.Item("Location" & i).Value =
..ItemData(.ItemsSelected.Item(i - 1))
Next i
End With

End Sub

HTH,

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top