Search code examples
ms-accessrequired

In Access, is the "falsepart" of the IIf Function required?


While converting some Access queries to T-SQL, I came across the Access function IIf. I read the documentation here and understand it takes 3 parameters: the expression, the if true, and the if false. What I have yet to find is if the "false" param is required? And if a false is not provided, what is the behavior?

UPDATE: When this question was asked, I did not know if the query worked with only 2 parameters (b/c I can not run the query in Access). I did, however, suspect it might work (with only 2 params) b/c a few queries I am converting (to T-SQL) have nested IIF's and the last IIF has only 2 params.


Solution

  • It's IIf, not IFF. All arguments are required in VBA and textbox expressions and both must be calculatable (no error result such as DivBy0) because both parts will be calculated - if either errors, the entire expression errors. The IIf() in Access query works differently - 'falsepart' calculates only if 'truepart' fails and if 'falsepart' is not provided, expression returns Null if 'truepart' fails.

    Try some expressions and see what happens. One for testing: IIf(1=2,"T").