Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Macros / December 2005

Tip: Looking for answers? Try searching our database.

Execute macro with criteria

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dennis Cheung - 28 Dec 2005 09:11 GMT
i had 2 macros. if [field A]. [tbl01]=1, excute macro1, if [field A].
[tbl01]=2, excute macro2. how can it be done? thanks!
Signature

Dennis Cheung

Steve Schapel - 28 Dec 2005 18:17 GMT
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

Signature

Steve Schapel, Microsoft Access MVP

> i had 2 macros. if [field A]. [tbl01]=1, excute macro1, if [field A].
> [tbl01]=2, excute macro2. how can it be done? thanks!
Dennis Cheung - 29 Dec 2005 01:40 GMT
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?
Signature

Dennis Cheung

> Dennis,
>
[quoted text clipped - 8 lines]
> > 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 - 29 Dec 2005 03:04 GMT
Dennis.

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

Signature

Steve Schapel, Microsoft Access MVP

> 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 - 29 Dec 2005 04:05 GMT
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

> Dennis.
>
[quoted text clipped - 5 lines]
>> that it cannot find field A in my expression. i think i write it
>> incorrectly. can u help?
Steve Schapel - 29 Dec 2005 06:06 GMT
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?

Signature

Steve Schapel, Microsoft Access MVP

> 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 Cheung - 29 Dec 2005 08:23 GMT
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

> Dennis,
>
[quoted text clipped - 18 lines]
>> macro 1 if field A in table tbl01=1 and run macro2 if field A in table
>> tbl01=2. thx again.
Steve Schapel - 29 Dec 2005 17:51 GMT
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

Signature

Steve Schapel, Microsoft Access MVP

> Steve,
>
[quoted text clipped - 3 lines]
> 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 Cheung - 30 Dec 2005 03:02 GMT
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

> Dennis,
>
[quoted text clipped - 14 lines]
>> 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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.