Using IN() with IIF in criteria

  • Thread starter Thread starter Dave Robinson
  • Start date Start date
D

Dave Robinson

I have a form with a checkbox for "A and B". The letters A and B are
possible values (the other possibilities are C and E) in a field of a table
upon which a query is based. I am trying to figure out how to write an iif
statement that will set the criteria for the field as IN("A","B") if that
checkbox is checked and IN("A","B","C") if it isn't checked.

I tried the following but I get a syntax error:

In (IIf([Forms]![Customizable On-Duty Personnel
Report]![ADay]=True,("A","B"),("A","B","C")))
 
Have a computed expression:

iif( Forms]![Customizable On-Duty Personnel
Report]![ADay], fieldName IN("A", "B"),
fieldName IN("A", "B", "C"))


and its criteria
<> 0




Vanderghast, Access MVP
 
Or use this construction.

FieldName in ("A","B") Or
FieldName = IIF(Forms]![Customizable On-Duty Personnel Report]![ADay],"C","")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Have a computed expression:

iif( Forms]![Customizable On-Duty Personnel
Report]![ADay], fieldName IN("A", "B"),
fieldName IN("A", "B", "C"))


and its criteria
<> 0




Vanderghast, Access MVP


Dave Robinson said:
I have a form with a checkbox for "A and B". The letters A and B are
possible values (the other possibilities are C and E) in a field of a
table
upon which a query is based. I am trying to figure out how to write
an iif
statement that will set the criteria for the field as IN("A","B") if that
checkbox is checked and IN("A","B","C") if it isn't checked.

I tried the following but I get a syntax error:

In (IIf([Forms]![Customizable On-Duty Personnel
Report]![ADay]=True,("A","B"),("A","B","C")))
 
I have a form with a checkbox for "A and B". The letters A and B are
possible values (the other possibilities are C and E) in a field of a table
upon which a query is based. I am trying to figure out how to write an iif
statement that will set the criteria for the field as IN("A","B") if that
checkbox is checked and IN("A","B","C") if it isn't checked.

I tried the following but I get a syntax error:

In (IIf([Forms]![Customizable On-Duty Personnel
Report]![ADay]=True,("A","B"),("A","B","C")))

Repeating my answer from yesterday, which you may not have seen:

You can't pass operators or delimiters or commas as a parameter - only actual
values. Try using Boolean logic:

WHERE
([Forms]![Customizable On-Duty Personnel Report]![ADay] = True
AND fieldname IN ("A", "B"))
OR
([Forms]![Customizable On-Duty Personnel Report]![ADay] = False
AND fieldname IN ("A", "B", "C"))
 
Back
Top