accessing a second column of a multiple select list box...

B

Brad Pears

I have a list box where the row source is an SQL "select" statment of two
columns from a table - the first column being an ID and the second column
being the ID description that the user is selecting. The user can select
multiple items in the listbox. I can access the ID portion of the listbox
(the 1st column) no probs using the mylstbox.itemdata(i) BUT how do I access
the 2nd column of a selected item using the .columns(x) format?? I tried
many different syntaxes and none seemed to work...

Example...
Table: Test
Fields: 2
FieldNames: "First" and "Last"
table data...
First Last
"Brad" "Pears"
"Terry" "Corbet"
"Paul" "Madden"


ListBox row source: "select * from TEST"
Columns:2
Bound Column: 1
Col Widths:2.54;2.54

The user selects items from the listbox and then the following code runs...

Private Sub Command0_Click()
Dim i As Variant
For Each i In mylstbox.ItemsSelected
' Displays the data in the first column only (i.e. the first names)
MsgBox mylstbox.ItemData(i)
' Now I would also like to display the data in column 2 (the last names)
msgbox ?????????
Next i
End Sub


Any help would be most appreciated!


Thanks,

Brad
 
W

Wayne Morgan

Try

MyListbox.Column(1, i)

Both indexes are zero based, so 1 is the second column. The ItemData index
is also zero based, so just using "i" should work.
 
B

Brad Pears

Works like a top!!! I completely missed the ability to specify the index
portion after the column number when using the .column method...

Thanks for that!

Brad
 

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