how to check if the result of a query = 0 records?

  • Thread starter Thread starter A.J.M. van Rijthoven
  • Start date Start date
A

A.J.M. van Rijthoven

I want to open a form that is based on a query. When the output of the
query results in 0 records, I don't want to open the form but just
display a messagebox. Is there a way to check if the result of the
query = 0 records??
 
You can put the following code in the OnOpen event of your form:

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


hth,
 
Hello TC,

Using Access 2002, this works just fine in the Open Event because there is a
Cancel argument. I do not see a Cancel argument in the Load event, so
slightly different code would be needed there, I suppose.
 
Hi Cheryl

I thought (from memory) that the form's recorset was not opened until the
Load event. But I don't have Access here to check, & my PC at home blew up
yesterday! (grrrrrrrrr). You're sure that recordsetclone is ok from the Open
event?

Cheers,
TC
 
Yep. Tested in a real, actual database with code behind the Open event of
the form. In my posts, I try always to mention - if I'm offering code that
I have not tested or am offering from memory - that it is untested.

Sorry to hear about your PC; hope you are up and running with something new
and snazzy really soon.
 
Ok, thanks for the info. & good wishes!

My previous PC also fried (some time ago). I'd taken regular, discipled
backups for years, but had recently changed my backup strategy. As a result,
I had not taken a proper backup for some months - & had done loads of
changes in that period.

Result: AUD$2,000 to a specialist data recovery service :-(((((((((

This time I have *recent* backups ....

Cheers,
TC
 
Back
Top