The IIf function-which returns one of two values determined by logical test-has this syntax: IIf(Expression, TruePart, FalsePart). At first, it might seem like an ideal shortcut for an If…Else…End If block. However, IIf is designed to execute both the True part and the False part. To verify, copy this into your Debug window and press enter:
? IIf(True, MsgBox("True Part"), MsgBox("False Part"))
Obviously, it’s extremely inefficient-and possibly error-inducing-to place functions in the True and False parts of IIf, because they are both executed. In general, always use a standard If…Else…End If block instead.