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.
            Asked
            
        
        
            Active
            
        
            Viewed 4.0k times
        
    3 Answers
16
            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"
 
    
    
        HansUp
        
- 95,961
- 11
- 77
- 135
7
            
            
        The code
If ListBox.ListIndex = -1 then
  MsgBox "Nothing selected"
end if
should help...
 
    
    
        Manuel Allenspach
        
- 12,467
- 14
- 54
- 76
- 
                    Thanks for sharing. but it seems not be working if I select and deselect an item from the list box. the listIndex increases to 1 in this case. – got2nosth Jan 10 '14 at 10:42
0
            
            
        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
 
    