IIf Criteria Question in a Query

T

Tom

In a Query, I have a Text Field named Brand that gets it's value from a
drop down box on a Form, [Forms]![Main Form]![CompBrand].

I have another Field in the query named ProductLine that is an Integer. If
the Brand is a certain name, I want one number result and if not, another
number result.

I tried this statement on the Criteria Line for ProductLine:
IIf([Forms]![Main Form]![CompBrand]="BrandX",302 or 312,312)

Neither one of the alternatives will pass as criteria to ProductLine. If I
enter 302 or 312 on the Criteria Line for ProductLine, all is fine.

I am thinking there is a syntax error. Am I close?

TIA!
 
K

Ken Snell [MVP]

You need this:

IIf([Forms]![Main Form]![CompBrand]="BrandX",302, 312) OR IIf([Forms]![Main
Form]![CompBrand]="BrandX",312,312)

Or more simply:

312 OR IIf([Forms]![Main Form]![CompBrand]="BrandX",302,312)
 
T

Tom

You need this:

IIf([Forms]![Main Form]![CompBrand]="BrandX",302, 312) OR IIf([Forms]![Main
Form]![CompBrand]="BrandX",312,312)

Or more simply:

312 OR IIf([Forms]![Main Form]![CompBrand]="BrandX",302,312)

Ken,

Thank you. That works nicely! One more question. How many ORs can I add
for additional Brands, i.e. BrandY? Would this work?

312 OR IIf([Forms]![Main Form]![CompBrand]="BrandX",302,312) OR
IIf([Forms]![Main Form]![CompBrand]="BrandY",302,312)

Tom
 
J

John W. Vinson

Thank you. That works nicely! One more question. How many ORs can I add
for additional Brands, i.e. BrandY? Would this work?

312 OR IIf([Forms]![Main Form]![CompBrand]="BrandX",302,312) OR
IIf([Forms]![Main Form]![CompBrand]="BrandY",302,312)

If all of the brands give the same outcome you can use a different syntax:

IIF([Forms]![Main Form]![CompBrand] IN ("BrandX", "BrandY"), 302, 312)
 
T

Tom

Thank you! That should do nicely if I have to add Brands.



Thank you. That works nicely! One more question. How many ORs can I add
for additional Brands, i.e. BrandY? Would this work?

312 OR IIf([Forms]![Main Form]![CompBrand]="BrandX",302,312) OR
IIf([Forms]![Main Form]![CompBrand]="BrandY",302,312)

If all of the brands give the same outcome you can use a different syntax:

IIF([Forms]![Main Form]![CompBrand] IN ("BrandX", "BrandY"), 302, 312)
 

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

Top