How to determine if any row is selected in a listbox

got2nosth picture got2nosth · Jan 10, 2014 · Viewed 32.6k times · Source

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.

Answer

HansUp picture HansUp · Jan 10, 2014

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"