Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if any row is selected in a listbox

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.

like image 258
got2nosth Avatar asked Jan 10 '14 07:01

got2nosth


People also ask

How do I know if an item is selected in ListBox?

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).

Which method is used to know the option selected from a ListBox?

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.


2 Answers

The code

If ListBox.ListIndex = -1 then
  MsgBox "Nothing selected"
end if

should help...

like image 119
Manuel Allenspach Avatar answered Sep 27 '22 00:09

Manuel Allenspach


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"
like image 23
HansUp Avatar answered Sep 26 '22 00:09

HansUp