Execute a macro inside an IIF statement

G

Guest

Can I execute a macro inside an IIF statement in an expression like this:

iif([field1] is null,EXECUTE MACRO-1,iif([field2] is not null,EXECUTE
MACRO-2))

What would I type instead of EXECUTE MACRO-1 to make the macro fire off?
 
G

Guest

don't think you can do it this way.
Basically because your query is written in a SQL-esque type language which
won't tie in to the access macros.

you could do it using VBA code however...

if isnull(me![Field1]) then
DoCmd.RunMacro "MacroName"
else
DoCmd.RunMacro "DifferentMacroName"
end if

but you'd need a trigger to call the VBA (maybe on the after update of field
1?)
fire off?
 
P

Paul Overway

It isn't clear where you are using this IIF. In a query? In code? Also,
what value is the IIF supposed to return? Your logic is questionable too.
What value is the IIF supposed to return if neither condition is met?

In any case, you probably need to create VBA functions...i.e.,

iif([field1] is null,DoSomething1(),iif([field2] is not
null,DoSomething2()))

However, given the question of how you are using this, that may not be
necessary at all.

If IsNull([Field1]) Then
'Do something here
Else
'Do something else here
End If

If IsNull([Field2])=False Then
'Do something here
Else
'Do something else here
End If
 
N

Nikos Yannacopoulos

You can't do it this way, but there are most likely several ways you can
achieve the desired result. Care to give some details of what youare
trying to achieve, and in what context?

Nikos
 

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


Top