Run query based on results of previous query using code

H

H J

I have a database with 6 queries, currently I have to manually run each of
these, but I want to automate them by clicking a button and letting them all
do their job.

The problem is that on one of them, I need to review the results before
proceeding with the next one. But, I only need to review the results if
there are any, if the query comes up empty, all is good and I can continue.

How can I code this so that if the query A returns no results, query B runs,
if query A has results, then those results are displayed and query B does
not run (I do not need to run query B until query A has no results).

Thanks.
 
B

Bob Barrows

H said:
I have a database with 6 queries, currently I have to manually run
each of these, but I want to automate them by clicking a button and
letting them all do their job.

The problem is that on one of them, I need to review the results
before proceeding with the next one. But, I only need to review the
results if there are any, if the query comes up empty, all is good
and I can continue.

How can I code this so that if the query A returns no results, query
B runs, if query A has results, then those results are displayed and
query B does not run (I do not need to run query B until query A has
no results).
Are you using ADO, DAO or RunQuery to run these queries?
 
S

Skip

How about (air code):

DBEngine(0)(0).Execute "QueryA", dbFailOnError
If StatusMsg(DBEngine(0)(0).RecordsAffected = 0 then
DBEngine(0)(0).Execute "QueryB", dbFailOnError
Else
docmd.OpenQuery "QueryA"
End If
 
H

H J

Thank you, this method worked perfectly (after I installed DAO)... I tested
with 0 values, and with values, both ways work as expected.

Thanks,
 
S

Skip

Good to hear. Thanks for the feedback. :)

H J said:
Thank you, this method worked perfectly (after I installed DAO)... I
tested with 0 values, and with values, both ways work as expected.

Thanks,
 

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