This Access tutorial explains how to use the Access iif function with syntax and examples.
The Microsoft Access iif function returns one value if a specified condition evaluates to TRUE, or another value if it evaluates to FALSE.
The syntax for the Microsoft Access 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.
The iif function can be used in the following versions of Microsoft Access:
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 Microsoft Access.
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.
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".
(scroll to see more)