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!
[tbl01]=2, excute macro2. how can it be done? thanks!
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!
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?
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.
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?