Test if query returns any records

J

Jon

Hi all

I need to check if a saved query returns any records before opening a form
that uses it as a record source. I realise this I could use DCount like
this:

If DCount("*","QueryName") > 0 Then

but is this the most *efficient* way if the query returns thousands of
records ?

Many thanks

Jon
 
A

Allen Browne

Do you have a field that will always contain a value, such as a primary key
field?

If so you could use:
If Not IsNull(DLookup("ID", "QueryName")) Then
since the field will only be Null if there is not at least one record.
 
J

Jon

Thanks Allen

Probably the fastest reply I've ever had to a posting !

Yes, my query includes a primary key field so your suggestion worked right
off.

Thanks again

Jon
 

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