Message box is no records found (1 Viewer)

JPR

Registered User.
Local time
Today, 05:31
Joined
Jan 23, 2009
Messages
192
Hello,
I am sure this has been discussed many times, but still having some problems in finding a solution for my db.

My form (frmMenu) has 4 textboxes, 4 cmd buttons and a unique listbox. Textboxes are used to type the queries criteria (I have 4 different queries).
The form also has another textbox that I use to count records in the listbox (txtsearchCount).
Below is an example of the code I am using behind a cmdbutton:

If Len(LNameSearch) & "" > 0 Then
Me.lstsearch.RowSource = "qryLname"
Me.lstsearch.Requery
Me.txtsearchCount = Me.lstsearch.ListCount - IIf(Me.lstsearch.ListCount = 0, 0, 1)
Me.txtsearchCount.Visible = True
End If

What I am trying to do is to add a simple msg box at the beginning of the code that will tell users if no records have been found. Something like this
if me.lstsearch has nor records (or the result of my query is 0 records, then......

MsgBox "Sorry, no records were found.", vbInformation, "Search Menu"

THank you
 

bastanu

AWF VIP
Local time
Today, 05:31
Joined
Apr 13, 2010
Messages
1,401
Use dCount:
Code:
If dCount("*",Me.lstsearch.RowSource)=0 then

      MsgBox "Sorry, no records were found.", vbInformation, "Search Menu"

     Exit Sub

Else

Cheers,
Vlad
 

Micron

AWF VIP
Local time
Today, 08:31
Joined
Oct 20, 2018
Messages
3,476
Don't see how you can do this at the beginning of your code because at that point, the listbox has no records because the query to populate it hasn't run yet, no?
I might try
Code:
If Len(LNameSearch) & "" > 0 And DCount("*", "qryLname")> 0 Then
  do stuff
Else
  msgbox
End If

or

Code:
If Not Len(LNameSearch) & "" > 0 And Not DCount("*", "qryLname")> 0 Then
  msgbox
  Exit Sub
End If

do stuff
 

Users who are viewing this thread

Top Bottom