Execute macro with criteria

G

Guest

i had 2 macros. if [field A]. [tbl01]=1, excute macro1, if [field A].
[tbl01]=2, excute macro2. how can it be done? thanks!
 
S

Steve Schapel

Dennis,

Make a third macro, with 2 RunMacro actions, one for each of the two
macros macro1 and macro2. In design view of the macro, if you can't see
a column for Conditions, select it from the View menu. In the Condition
column for the RunMacro action for macro1, enter...
[field A]=1
.... and in the Condition column for the RunMacro action for macro2, enter...
[field A]=2
 
G

Guest

Steve,

I enter [field A]. [tbl01]=1 in the conditions field, Access prompt me that
it cannot find field A in my expression. i think i write it incorrectly. can
u help?
--
Dennis Cheung


Steve Schapel said:
Dennis,

Make a third macro, with 2 RunMacro actions, one for each of the two
macros macro1 and macro2. In design view of the macro, if you can't see
a column for Conditions, select it from the View menu. In the Condition
column for the RunMacro action for macro1, enter...
[field A]=1
.... and in the Condition column for the RunMacro action for macro2, enter...
[field A]=2

--
Steve Schapel, Microsoft Access MVP


Dennis said:
i had 2 macros. if [field A]. [tbl01]=1, excute macro1, if [field A].
[tbl01]=2, excute macro2. how can it be done? thanks!
 
D

Dennis Cheung

Steve,

i am sorry that i didn't make it very clear. field A is the field name a
field in a table and its table name is tbl01. i need the macro to run macro
1 if field A in table tbl01=1 and run macro2 if field A in table tbl01=2.
thx again.

Dennis


Steve Schapel said:
Dennis.

What is field A? What is tbl01? What is [field A]. [tbl01]?

--
Steve Schapel, Microsoft Access MVP


Dennis said:
Steve,

I enter [field A]. [tbl01]=1 in the conditions field, Access prompt me
that it cannot find field A in my expression. i think i write it
incorrectly. can u help?
 
S

Steve Schapel

Dennis,

I had assumed you were running the macro from an event on a form. If
so, by putting the Condition like I suggested before...
[field A]=1
.... will refer to the value of field A in the current record in the form.

You can't refer to the value of the field in a table in the way you
have. It is incorrect syntax, and anyway, Access would need to know
which record in the table you are talking about before it could be
evaluated - if you see what I mean. You could use a Domain Aggregate
Function, such as DLookup() or DMax(), in the macro Condition, to refer
to the value of field A in a particular record in the table. So, sorry,
I still have question for you... Where are you calling the macro? And
how do you know which record in the table to see the field A value?
 
D

Dennis Cheung

Steve,

Both Macro1 and Macro2 are openquery event. In table1, there is only one
record in it. I thought Access would know which record match the criteria.
But your question made me understand i was wrong. since there could be more
than one record in table1. I may try to use the Dlookup(), but i'd never
used this function before. would you let me know more details?

Dennis

Steve Schapel said:
Dennis,

I had assumed you were running the macro from an event on a form. If so,
by putting the Condition like I suggested before...
[field A]=1
... will refer to the value of field A in the current record in the form.

You can't refer to the value of the field in a table in the way you have.
It is incorrect syntax, and anyway, Access would need to know which record
in the table you are talking about before it could be evaluated - if you
see what I mean. You could use a Domain Aggregate Function, such as
DLookup() or DMax(), in the macro Condition, to refer to the value of
field A in a particular record in the table. So, sorry, I still have
question for you... Where are you calling the macro? And how do you know
which record in the table to see the field A value?

--
Steve Schapel, Microsoft Access MVP


Dennis said:
Steve,

i am sorry that i didn't make it very clear. field A is the field name a
field in a table and its table name is tbl01. i need the macro to run
macro 1 if field A in table tbl01=1 and run macro2 if field A in table
tbl01=2. thx again.
 
S

Steve Schapel

Dennis,

When I asked about 'event', I meant when is the macro run, for example
Click event of a command button. OpenQuery does not mean the event,
this is the Action in the macro.

Try the macro condition like this...
DLookup("[Field A]","tbl01")=2
 
D

Dennis Cheung

Steve,

The event is a click event of a command button. And The Dlookup works fine.
It does what i need. Thanks for your support.

Dennis Cheung

Steve Schapel said:
Dennis,

When I asked about 'event', I meant when is the macro run, for example
Click event of a command button. OpenQuery does not mean the event, this
is the Action in the macro.

Try the macro condition like this...
DLookup("[Field A]","tbl01")=2

--
Steve Schapel, Microsoft Access MVP

Dennis said:
Steve,

Both Macro1 and Macro2 are openquery event. In table1, there is only one
record in it. I thought Access would know which record match the
criteria.
But your question made me understand i was wrong. since there could be
more
than one record in table1. I may try to use the Dlookup(), but i'd never
used this function before. would you let me know more details?
 

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

Similar Threads

How to create new Actions for Macros in Access 2007 1
Run macros based on list box selection 0
Macro to Auto run 1
Run all macro 4
Stop Command Question 4
Two in report 1
Macro conflict 4
Macro conflict 1

Top