Cancel Event for no data in Macro?

S

sonofroy

I have a Macro that is running a query and then emails the report associate
to a person. I would like to see if it is possible to cancel this event if no
records are returned in the query? THanks
 
S

Steve Schapel

Sonofroy,

You can use a Condition in your macro like this:
DCount("*","NameOfQuery")>0
This means the macro will nony run if there are records returned by the
query. "NameOfQuery" refers to the name of the query that the report is
based on. I am not sure what exactly you mean by "running a query" in your
original question, but assuming this is an action query, that this is not
the query I am referring to, I mean the Record Source of the report.
 
S

sonofroy

Yes the first step in the Macro is to run an action query and the next step
is to send a report by email. I wanted to stop the macro completely if the
before the email if the action returns no results.
 
S

Steve Schapel

Sonofroy,

Ok, that's fine. Well, my earlier reply is applicable. Use what I showed
you as the Condition for the first action in the macro after the OpenQuery,
and then put ellipsis (...) in the Condition for all actions after that.

An alternative approach would be to put like this in the Condition:
DCount("*","NameOfQuery")=0
.... and put this for a StopMacro action, straight after the OpenQuery.

As I said before, substitute the actual name of the query for my
"NameOfQuery", but this is not the action query, it is the query the report
is based on.

Make sense?
 

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