using If,then, else statement in a macro

S

shea@pitt

I have a macro can run one of 2 queries. I want to use the Conditions in my
macro to determine which query to run.
this is what it look like:

Run Query ([Forms]![frmSelectCriteria]![cboTeam]) OpenQuery-
(qryNotesbyTeam)
([Forms]![frmSelectCriteria]![cbocategory]) OpenQuery-
(qryNotesbyCategory)

I have this Run Query linked to my OK button on my dialog form. when
cboTeam is not valued, qryNotesbyTeam still runs 1st. If I put in a
statement to stopmacro after the 1st query, the 2nd query will never run,
which means if I value cboCategory, I will never get my query results.

I try entering IF or WHERE and I get error "the expression you entered has a
function name that Microsoft Access can't find."

Any help will be greatly appreciatged
 
S

Software-Matters via AccessMonster.com

Hi,
Could you post the code with the IF statement in and highlight the line that
Access doesn't like.
Regards

shea@pitt said:
I have a macro can run one of 2 queries. I want to use the Conditions in my
macro to determine which query to run.
this is what it look like:

Run Query ([Forms]![frmSelectCriteria]![cboTeam]) OpenQuery-
(qryNotesbyTeam)
([Forms]![frmSelectCriteria]![cbocategory]) OpenQuery-
(qryNotesbyCategory)

I have this Run Query linked to my OK button on my dialog form. when
cboTeam is not valued, qryNotesbyTeam still runs 1st. If I put in a
statement to stopmacro after the 1st query, the 2nd query will never run,
which means if I value cboCategory, I will never get my query results.

I try entering IF or WHERE and I get error "the expression you entered has a
function name that Microsoft Access can't find."

Any help will be greatly appreciatged
 
S

Steve Schapel

Shea,

It is not clear what you are trying to achieve. Do you mean you have this
in the Condition for the first OpenQuery action?...
[Forms]![frmSelectCriteria]![cboTeam]

If so, what do you mean? You mean you only want the query to run if there
is an entry in the cboTeam control? So if the cboTeam control has no data,
the query does not run? If so, the Condition would be:
[Forms]![frmSelectCriteria]![cboTeam] Is Not Null

Where are you running this macro from anyway? If it's from an event on the
frmSelectCriteria form, then you don't need all that form reference anyway.
Condition:
[cboTeam] Is Not Null

If I am barking up the wrong tree, please give some more details, maybe with
specific example, of what you want to happen. 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