test for Null query result in VBA

  • Thread starter Thread starter MJH
  • Start date Start date
M

MJH

I created a queary in Access 2003. How do I test for a possible Null result
from running the query, i.e. no records, using VBA code?

thanks
 
One way is to use the DCount function to see how many records are returned
by the query. A value of 0 means no records.

NumberOfRecordsReturned = DCount("*", "QueryName")
 
Another way would be if you are creating a recordset using that query, test
for BOF And EOF of the recordset. If you're at both the beginning and end of
the recordset at the same time then there are no records in the recordset.

If rst.BOF And rst.EOF Then
'no records
Else
'continue
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

Back
Top