Determining number of records returned...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

We have a lookup form on which a user can specify a portion of (or all of)
three various fields. The customers last name, first name and phone#.

When the user clicks "find", the following code is run...

' Apply the filter
DoCmd.ApplyFilter "qryFindCustomer"

The query "qryFindCustomer" uses the "like" clause for the three fields I
referred to above in order to return the appropriate records.

My question is, is there a quick way I can then check to see if no records
were returned from the query and hence inform the user of this?

Thanks,

Brad
 
If you paste this function into a standard module, you can use it to count
records in any table (or a select query):

'************************
Function CountRecords(TheTable As String) As Long
CountRecords = DCount("*", TheTable)
End Function
'************************

Then to use it, something like:
'************
If CountRecords("qryFindCustomer") = 0 Then
MsgBox "There are no records"
Else
MsgBox "Records were found"
End If
'*************
 
Back
Top