Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox - how to reference 2nd column of selected item?

Status
Not open for further replies.

lorirobn

MIS
Mar 15, 2005
450
US
Hi,

I have a listbox on a form. It has 1 column, and I am adding a 2nd column, hidden, that I can use to get info from the selected item. Its row source is a value list. I have set it up, but how do I reference the 2nd column on the item selected, so that I can get the data in there?

My ListBox is lstReport.
Do I use lstReport.Selected somehow? I know I'd use column(1) for the 2nd column, but how do I reference the row that has been selected? How do I know this row?

Thanks in advance!
Lori
 
Me.lstReport.Column(1) should get you the second column of the lstReport's selected item.
 
Hi rjoubert -

I tried doing what you suggested, but it seems to always give me a zero (0), regardless of which list item I select. Even if I try me.lstReport.Column(0), the results are zero.

??? am I doing something wrong?

Thanks for the response,
Lori
 
am I doing something wrong?
You probably play with a MultiSelect ListBox, so have a look at ItemsSelected ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
If you are using a multiselect listbox, as PHV has suggested, try this code...

Code:
    Dim frm As Form, ctl As Control
    Dim varItm As Variant

    Set frm = Forms!YourFormName
    Set ctl = frm!lstReport
    For Each varItm In ctl.ItemsSelected
        Debug.Print ctl.Column(1, varItm)
        Debug.Print
    Next varItm
 
Hi - the MultiSelect property = None.
any other suggestions?
meanwhile I will play around with it later on when I get a chance.
Thanks!
Lori
 
This may be a silly question, but are you sure you have a record selected in your list box?
 
Hi r -

Argghhh!!! Don't know where my head was at yesterday. I knew it had to be my mistake...and just found it. I was using lstReport.Selected(1) instead of lstReport.Column(1), I'm embarrassed to say!

Thanks to you all so much - thanks for sticking through it with me...

Hopefully I am more focused today...
Lori
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top