Check that no records are selected in a listbox (1 Viewer)

brharrii

Registered User.
Local time
Today, 13:31
Joined
May 15, 2012
Messages
272
I have button on my form that uses a selected record in a listbox (non multi-select) to run code that updates a table. The code itself works great so long as there is a record selected in the listbox. If no record is selected an error is thrown. I'd prefer the end user not to ever see that error. If the end user clicks the button and no records are selected, I'd like for nothing to happen at all. I've tried several variations of checking the listbox with an if / then statement to see if records are selected and if so to exit sub, but they all throw errors when no record is selected in the listbox.

Code:
If IsNull(Me!lstHeatTreatments) Then
    Exit Sub
End If

Code:
If IsNull(Me.lstHeatTreatments) Then
    Exit Sub
End If


Code:
If Me.lstHeatTreatments.Selected = False Then
     Exit Sub
End If
 

pr2-eugin

Super Moderator
Local time
Today, 21:31
Joined
Nov 30, 2011
Messages
8,494
Try this.
Code:
If Me.lstHeatTreatments.ItemsSelected.Count = 0 Then Exit Sub
 

brharrii

Registered User.
Local time
Today, 13:31
Joined
May 15, 2012
Messages
272
Beautiful, that worked.

Thank you
 

Users who are viewing this thread

Top Bottom