In code check to see if query has no records

J

John

If someone could help with some code to look to see if a
query has no records. The reason is because if there are
records I want to show those records and if there is not
then I want to pop-up another box.

Thanks in advance
 
K

Kailash Kalyani

One way to test if a query has no records is to open it using ADO/DAO and
check if you've reached EOF. If so then no records exist.
 
H

Howard Brody

Dim i As Intege
i = DCOUNT("[Field]","[QueryName]"
If i = 0 The
MsgBox ....
End I

----- John wrote: ----

If someone could help with some code to look to see if a
query has no records. The reason is because if there are
records I want to show those records and if there is not
then I want to pop-up another box

Thanks in advance
 
C

Cheryl Fischer

If your Query is the RecordSource of a Form, you can put the following code
in the Open event of the Form:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records to review."
Cancel = True
End If

If there are no records in the query, the form does not open and the message
box is displayed for the user.
 

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