Need help with ListBox

sjslall

Registered User.
Local time
Yesterday, 16:06
Joined
Oct 21, 2010
Messages
34
Listbox setup as value list
Need to populate the listbox with items and each item has a special integer code associated with it.
How can we assign the code to each item in the listbox and also how can we extract which item has been selected in the click event (multiselect is disabled) so that we get the selected item's code

Example:

set rs=currentdb().openrecordset("Select item_name, item_id from items")
do while not rs.eof
lstitems.additem rs![item_name] << would like to add the item_id as an identifier to this item>>
loop

Thanks
 
Not quite clear on your objective sjsall. If you have these values in a table why don't you just set the Row Source Type to Table/Query and use a SELECT query as the Row Source?
 
I agree, will try this out
 
normally in a list box, you would have (say) 2 columns.

first column is the id
second column is the description

set the width of the first column to 0. then you dont see the id, and only the description is seen.

but the list box id is still bound to the hidden first column. (although you can bind to any column)

note that the columns are zero based

so

mylistbox 'assuming the listbox is bound to column 1 AND
mylistbox.column(0) - both return the value of the first column

mylistbox.column(1) - returns the value of the second column (normally the first visible column)

columns are even more flexible than this, but i think this is what you are loooking for
 

Users who are viewing this thread

Back
Top Bottom