Home page
or browse popular tags
Access Functions

Sign up for the free email newsletter for new tips, tutorials and more. Enter your email address below, and then click the button.

Privacy Policy

RSS Twitter

Access: IIF Function


In Access, the IIF function returns one of two arguments depending on the evaluation of an expression.

The syntax for the IIf function is:

IIf ( expression, truepart, falsepart )

IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.

expression is the value that you want to test.

truepart is the value returned if expression evaluates to TRUE.

falsepart is the value returned if expression evaluates to FALSE.


IIf ([Price] > 400, "expensive", "cheap")      Returns "expensive" if the value in the Price field is
                                               greater than 400. Otherwise, returns "cheap".

VBA Code

If [Price] > 400 Then
End If

This is equivalent to the following IF statement in VBA code. The preceding example uses the IIf function to evaluate the givven expression and returns the word "Expensive" if the amount is greater than 400; otherwise, it returns the word "Cheap".

SQL query

You can also use the iif function in a query.

SELECT SellerID, BuyerID, Item, IIf([Price]>400,[Price]*1.05,[Price]*1.15) AS Total
FROM Antiques

If you'd like to see how it works, enter SQL statement and press Execute


Add To: Add to dzone dzone | Digg this digg | Add to del.icio.us del.icio.us | Stumble it stumbleupon

  • Comments

Copyright © 2005-2023             www.WebCheatSheet.com All Rights Reserved.