views:

23

answers:

1

Guys...if I want to run a button click event that takes a list box and uses the ID field that is in the listbox in a SQL statement in VB, then is it

me.MyListbox.selected

or

me.MyListbox.value

to get that value? for some reason I have tried both and neither seem to be working. .value returns an empty value, and .selected generates an error stating the argument is not valid.

thanks justin

+3  A: 

If the ID is the bound column and the listbox is not multiselect, you can use just the name of the listbox without any other qualifier. If the ID is not the bound column, then use the column property to get the value : MyListBox.Column(n) where n is the column number starting from zero.

For multiselect listboxes, you need to iterate through the selected items to get a list to use with SQL.

If you are using the query design window or a control on a form or report, you cannot use Me, you must either use the full reference (Forms!Formname!ControlName) or for a control on the same form, just the name of the listbox.

Remou
can you ellaborate on iterating for a multi-select box. Other than that, it is working now so thanks very much!
Justin
See your previous question: http://stackoverflow.com/questions/3310904/ms-access-2007-cycling-through-values-in-a-list-box-to-grab-ids-for-a-sql-stat/3311022#3311022
Remou