Returns one of two values depending on the result of a specified logical expression.

Syntax

IIF(<expL>, <exp1>, <exp2>)

<expL>

The logical expression to evaluate to determine whether to return <exp1> or <exp2>.

<exp1>

The expression to return if <expL> evaluates to true.

<exp2>

The expression to return if <expL> evaluates to false. The data type of <exp2> doesn't have to be the same as that of <exp 1>.

Description

IIF( ) stands for "immediate IF" and is a shortcut to the IF...ELSE...ENDIF programming construct. Use IIF( ) as an expression or part of an expression where using IF would be cumbersome or not allowed. In particular, if you’re evaluating a condition to decide which value you want to assign to a variable or property, using IIF( ) involves less duplication (you don’t have to type the target of the assignment twice).

If <exp1> and <exp2> are true and false, in either order, using IIF( ) is redundant because <expL> must evaluate to either true or false anyway.