If Statement Query is empty Then Do...

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I have code that I want to do an If statement that looks at a query and IF
the query is empty I want it to end the if. Or I could do it the other way If
the query has data then execute the next step Else End If.

Ho would I write the IF statement?
 
K

Klatuu

The problem is you don't know how many rows the query is going to return
until you run it. A way to get around that would be to do a DCount on the
query using the exact same filtering criteria you use in the query. However,
this may not work for action queries. If it is one table, you could do the
Dcount against the query. If the query you are testing has multiple tables,
you may want to create a select query that pulls the fields involved in the
filtering criteria and Dcount against that.

So, it might go something like this:

If DCount("*","MyTestQuery) = 0 Then
MsgBox "No records to Process"
Else
'Run the query here
End If
 
E

eos

AUTO-REPLY From George Levitt

Please allow this to confirm a system receipt of your e-mail.

I am out of the office until Wednesday morning (1/12/05) and will not be
reviewing or responding to email or voicemail until that time.

I look forward to replying to your message on Wednesday.

Thanks and warmest regards, George
 
E

eos

AUTO-REPLY From George Levitt

Please allow this to confirm a system receipt of your e-mail.

I am out of the office until Wednesday morning (1/12/05) and will not be
reviewing or responding to email or voicemail until that time.

I look forward to replying to your message on Wednesday.

Thanks and warmest regards, George
 
Top