MS Access: iif Function
In Microsoft Access, the iif function returns one value if a specified condition evaluates to TRUE, or another value if it evaluates to FALSE.
The syntax for the iif function is:
iif ( condition, value_if_true, value_if_false )
condition is the value that you want to test.
value_if_true is the value that is returned if condition evaluates to TRUE.
value_if_false is the value that is return if condition evaluates to FALSE.
- Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000
iif ([Qty] > 10, "large", "small")
would return "large" if the value in the Qty field is greater than 10. Otherwise, it would return "small".
This is equivalent to the following IF statement in VBA code.
If [Qty] > 10 Then result = "large" Else result = "small" End If
You can use the iif function in a query.
In this example, if the [Time Out] field is less than or equal to 12 o'clock noon, then the iif function will return the number of hours that have elapsed between [Time Out] and [Time In]. If [Time Out] is greater than 12 o'clock noon, then the iif function will return subtract 30 minutes from the time worked.
Frequently Asked Questions
Question: How would I use the iif function if I wanted to have more than one condition?
Answer: You could use the AND keyword to include multiple conditions.
In the example above, the iif function will return "Yes" if both the ContactTitle = "Owner" and City = "Madrid". If one or both of these conditions is not met, it will return "No".