got2nosth
got2nosth

Reputation: 618

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.

Upvotes: 11

Views: 43912

Answers (3)

Ampersand Black
Ampersand Black

Reputation: 1

this worked for me...a mix of both comments before, thank you both

If List4.ItemsSelected.Count = 0 Then
  MsgBox "Nothing selected"

So if nothing is selected I get the message

Upvotes: 0

HansUp
HansUp

Reputation: 97100

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"

Upvotes: 17

Manuel Allenspach
Manuel Allenspach

Reputation: 12735

The code

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

should help...

Upvotes: 7

Related Questions