I have a list box in my Access form. I need to know if any of the rows in this list box has been selected by the user. Is there any simple Access property or method exists for this purpose? I do not want to loop through the listbox to check if any row's selected property is true, because I am only interested to know if a selection action is done.
To determine the items that are selected, you can use the Selected property of the list box. The Selected property of a list box is an array of values where each value is either True (if the item is selected) or False (if the item is not selected).
If you want to obtain the index position of the currently selected item in the ListBox, use the SelectedIndex property. In addition, you can use the SelectedIndices property to obtain all the selected indexes in a multiple-selection ListBox.
The code
If ListBox.ListIndex = -1 then
MsgBox "Nothing selected"
end if
should help...
A list box has the ItemsSelected
property which returns a read-only reference to the hidden ItemsSelected
collection. And you can ask for the Count
property of that collection ...
MsgBox Me.YourListBoxName.ItemsSelected.Count & " items selected"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With