IIF statement and multiple items

  • Thread starter Thread starter rookie
  • Start date Start date
R

rookie

I have 3 fields (see below) and each of them contains True or False. I was
trying to write a query that combined all of them and output only 1 of the 3
fields. For example, [WFL] = True, [Ab without Asp] = False, and [Ab w/ Asp]
= False. Therefore, the final output on my expression should say "WFL"
because it's True and the rest are false. I attempted to create an expression

[WFL]
[Ab without Asp]
[Ab with Asp]

MBS Findings: IIf([WFL] = "True" or [Ab without Asp] = "True" or [Ab with
Asp] = "True",.....)


I was lost afterwards since I knew i couldn't list 3 items after the
comma...Please help!!

Rookie
 
SWITCH( [wfl], "I used WFL",
[Ab without Asp], "I used Ab alone",
[Ab with Asp], "I used both Ab and Asp",
true, "I used something else, if I used anything")



Vanderghast, Access MVP
 
Hi Vanderghast,
If I'm not mistaken, the Switch function applies to VBA section.
unfortunately, I don't know how to use it. Can I use the switch function in
the expression builder?
If so, how do i write it? I don't get it...

thanks!
Rookie

vanderghast said:
SWITCH( [wfl], "I used WFL",
[Ab without Asp], "I used Ab alone",
[Ab with Asp], "I used both Ab and Asp",
true, "I used something else, if I used anything")



Vanderghast, Access MVP




rookie said:
I have 3 fields (see below) and each of them contains True or False. I was
trying to write a query that combined all of them and output only 1 of the
3
fields. For example, [WFL] = True, [Ab without Asp] = False, and [Ab w/
Asp]
= False. Therefore, the final output on my expression should say "WFL"
because it's True and the rest are false. I attempted to create an
expression

[WFL]
[Ab without Asp]
[Ab with Asp]

MBS Findings: IIf([WFL] = "True" or [Ab without Asp] = "True" or [Ab with
Asp] = "True",.....)


I was lost afterwards since I knew i couldn't list 3 items after the
comma...Please help!!

Rookie
 
Hi Vanderghast,
I did some more research and realized i can use switch in my expression
builder. However, it didn't work! Everything under MBS findings was "Ab
without Asp". What did i do wrong?

MBS Findings: Switch([Ab without Asp]=True,"Ab without Asp",[Ab with
Asp]=True,"Ab with Asp",[WFL]=True,"WFL")

thanks!
Rookie

vanderghast said:
SWITCH( [wfl], "I used WFL",
[Ab without Asp], "I used Ab alone",
[Ab with Asp], "I used both Ab and Asp",
true, "I used something else, if I used anything")



Vanderghast, Access MVP




rookie said:
I have 3 fields (see below) and each of them contains True or False. I was
trying to write a query that combined all of them and output only 1 of the
3
fields. For example, [WFL] = True, [Ab without Asp] = False, and [Ab w/
Asp]
= False. Therefore, the final output on my expression should say "WFL"
because it's True and the rest are false. I attempted to create an
expression

[WFL]
[Ab without Asp]
[Ab with Asp]

MBS Findings: IIf([WFL] = "True" or [Ab without Asp] = "True" or [Ab with
Asp] = "True",.....)


I was lost afterwards since I knew i couldn't list 3 items after the
comma...Please help!!

Rookie
 
Switch returns the first (leftmost) companion for the test which evaluates
to true, so I suspect it is simply the case that [Ab without Asp] is true.
So, even if the other tests are also true, only the companion of the first
test which evaluates to true would ever be returned.

Note that it is useless to test it = true, well, I assumed it is already
Boolean.


Vanderghast, Access MVP


rookie said:
Hi Vanderghast,
I did some more research and realized i can use switch in my expression
builder. However, it didn't work! Everything under MBS findings was "Ab
without Asp". What did i do wrong?

MBS Findings: Switch([Ab without Asp]=True,"Ab without Asp",[Ab with
Asp]=True,"Ab with Asp",[WFL]=True,"WFL")

thanks!
Rookie

vanderghast said:
SWITCH( [wfl], "I used WFL",
[Ab without Asp], "I used Ab alone",
[Ab with Asp], "I used both Ab and Asp",
true, "I used something else, if I used anything")



Vanderghast, Access MVP




rookie said:
I have 3 fields (see below) and each of them contains True or False. I
was
trying to write a query that combined all of them and output only 1 of
the
3
fields. For example, [WFL] = True, [Ab without Asp] = False, and [Ab w/
Asp]
= False. Therefore, the final output on my expression should say "WFL"
because it's True and the rest are false. I attempted to create an
expression

[WFL]
[Ab without Asp]
[Ab with Asp]

MBS Findings: IIf([WFL] = "True" or [Ab without Asp] = "True" or [Ab
with
Asp] = "True",.....)


I was lost afterwards since I knew i couldn't list 3 items after the
comma...Please help!!

Rookie
 
Back
Top