In code check to see if query has no records

  • Thread starter Thread starter John
  • Start date Start date
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
 
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.
 
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
 
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.
 
Back
Top