Using Or with an IIf Statement

D

dbad7

I am having trouble using an IIf statement as criteria. It seems simple
enough but does not work. I am using a Combo box to narrow down the condtion
of inventory. My combo box is simple: Good, Bad, All

HAVING
[CONDITION_NAME]=IIf([Forms]![frmMainNew]![cboCondInv]="Good",("Repaired" Or
"New"),IIf([Forms]![frmMainNew]![cboCondInv]="Bad","Defective" Or "BER" Or
"IN-Warranty" Or "To-Outsource",Like "*"))

Access is not letting me use Or in the Then clause, saying it's too
complicated. Is there another way to do this?
 
M

Marshall Barton

dbad7 said:
I am having trouble using an IIf statement as criteria. It seems simple
enough but does not work. I am using a Combo box to narrow down the condtion
of inventory. My combo box is simple: Good, Bad, All

HAVING
[CONDITION_NAME]=IIf([Forms]![frmMainNew]![cboCondInv]="Good",("Repaired" Or
"New"),IIf([Forms]![frmMainNew]![cboCondInv]="Bad","Defective" Or "BER" Or
"IN-Warranty" Or "To-Outsource",Like "*"))

Access is not letting me use Or in the Then clause, saying it's too
complicated. Is there another way to do this?


You can not include parts of an expression inside an IIf.
Each part of an And/Or must be a complete comparison.

I think this should do what you want. Note that I used two
different way to deal with an OR kind of situation to
provide examples.

IIf(Forms!frmMainNew!cboCondInv] = "Good", CONDITION_NAME =
"Repaired" Or CONDITION_NAME = "New",
IIf(Forms!frmMainNew!cboCondInv = "Bad", CONDITION_NAME
IN("Defective","BER","BER","IN-Warranty","To-Outsource"),
True)
 
Top