Determining number of records returned...

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
 
M

Mark M

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
'*************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top