Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple if statements

0 views
Skip to first unread message

Big Tony

unread,
Jul 12, 2004, 1:56:55 PM7/12/04
to
If I want to make an IIf statement that hinges more than
two situations (say three or four possible outcomes), is
it possible to embed IIF statements inside each other,
like you can in excel?

Ex: =IIF(x12=4,"GREEN",IIF(x12=3,"Blue",IIF
(x12=2,"RED","WHITE")))

In addition, is there perhaps an alternative, more
efficient way to do this?

fredg

unread,
Jul 12, 2004, 2:13:36 PM7/12/04
to

In a query you do NOT use the initial = sign.
If the criteria values are number datatypes:

Ex:IIf([FieldName]=4,"Green",IIf([FieldName]=
3,"Blue",IIf([Fieldname]=2,"White","No value")))

If the criteria values are text datatype surround them with double
quotes also:
Ex:IIf([FieldName]="4","White", etc.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.

Duane Hookom

unread,
Jul 12, 2004, 2:32:20 PM7/12/04
to
In this case, Choose() might be a better choice:
=Choose(x12, "WHITE","RED","Blue","GREEN")
Check Help for the syntax.

--
Duane Hookom
MS Access MVP
--

"Big Tony" <anon...@discussions.microsoft.com> wrote in message
news:2b27301c46839$9ea69b80$a501...@phx.gbl...

Gerald Stanley

unread,
Jul 12, 2004, 2:48:10 PM7/12/04
to
Nested IIf statements are perfectly fine. An alternative
is the SWITCH function that works with pairs of parameters;
the first being the condition and the second the action if
the condition is true. In your example, this would be

=Switch(x12>4,"WHITE",x12=4,"GREEN",x12=3,"Blue",x12=2,"RED",x12<2,"WHITE")

Hope This Helps
Gerald Stanley MCSD

>.
>

anon...@discussions.microsoft.com

unread,
Jul 12, 2004, 5:33:09 PM7/12/04
to
thank you, very helpful

>.
>

anon...@discussions.microsoft.com

unread,
Jul 12, 2004, 5:32:50 PM7/12/04
to
thank you, very helpful

>.
>

0 new messages