See Also Example
Description
Returns one of two parts depending on the evaluation of an expression.
Syntax
IIf( expr, truepart, falsepart )
Remarks
The IIf function has the following parts:
Argument Description
expr Expression you want to evaluate.
truepart Value or expression returned if expr is True.
falsepart Value or expression returned if expr is False.
You might use IIf (meaning "Immediate If") to evaluate an expression and return either of two other values. For example, you could use the IIf function to inspect a field on a form and determine whether it is Null . If it is, you might have the function return an empty string; otherwise, it would return the field's contents. The following example checks a field in the copy buffer:
IIf(IsNull(Data1.Recordset("State")), "",Data1.Recordset("State"))
IIf is most useful in the Validate event. The If...Then...Else statement often offers more versatility. IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.