listbox selected value

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

Guest

Hi,
I am using access 2002.
How can I find out the value of the current selected item in a listbox.
Thanks, M
 
mark said:
Hi,
I am using access 2002.
How can I find out the value of the current selected item in a
listbox. Thanks, M

If the list box is not set for multiselect, the value of the list box
control itself is the value of the item that is currently selected. If
no item is selected, the value of the list box is Null.

If the list box is set for multiselect, there can be more than one
selected item and the list box has no value. In that case you can loop
through the control's ItemsSelected collection and get the ItemData
value for each row in the collection. Post back if you need details on
how to code this.
 
If the Multiselect property is set to None, you can simply refer to the
listbox by name to get its value (strSelected = Me.MyListbox)

When the MultiSelect property is set to Extended or Simple, you can use the
list box's Selected property or ItemsSelected collection to determine the
items that are selected. The value of the list box control will always be
Null, even if only one item has been selected

Dim intCurrentRow As Integer

For intCurrentRow = 0 To Me.MyListbox.Listcount - 1
If Me.MyListbox.Selected(intCurrentRow) Then
Debug.Print Me.MyListbox.Column(0, intCurrentRow)
End If
Next intCurrentRow

or

Dim varItm As Variant

For Each varItm In Me.MyListbox.ItemsSelected
Debug.Print ctl.ItemData(varItm)
Next varItm
 
Back
Top