This MSAccess 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 iif function in MS Access 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:
Let's look at how to use the iif function in MS Access:
iif ([Qty] > 10, "large", "small")
This example 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 query, we have used the iif function as follows:
Hours: IIf([Time Out]<#12:00:00 PM#,([Time Out)-[Time In])*24,(([Time Out]-[Time In])*25)-0.5)
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 subtract 30 minutes from the time worked.
The results of the iif function will be displayed it in a column called Hours.
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)