Getting more than 1 column from a listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a multi select listbox that has 2 columns (Name and NameID - Name is a
string and NameID is a number).

The number value is the bound column and I can get those numbers out just fine
using a For Next loop and saving them in a string (strNameID).

What I cant figure out is how to get the Name column in a For Next loop.

Here is the VB code i use to get the NameID:

For Each varItem in Me.lstbox.ItemSelected
strNameID = strNameID & "," & me.lstbox.ItemData(varItem) &""
Next varItem

Thanks,
Joel
 
Here is an example for you:

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant

Set frm = Me.Form
Set ctl = Me.MyListBox

For Each varItem In ctl.ItemsSelected
Debug.Print ctl.Column(0, varItem)
Debug.Print ctl.Column(1, varItem)
Next varItem
 
Thanks a bunch Matt, that worked great.

Joel

Matt said:
Here is an example for you:

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant

Set frm = Me.Form
Set ctl = Me.MyListBox

For Each varItem In ctl.ItemsSelected
Debug.Print ctl.Column(0, varItem)
Debug.Print ctl.Column(1, varItem)
Next varItem
 
Back
Top