iif - immediate if

If-Then-Else function.

Syntax
      iif (condition, value_if_true, value_if_false)

Key
   condition      The expression to test.
                  For multiple conditions use AND / OR

   value_if_true  The value returned if condition evaluates to TRUE.

   value_if_false The value returned if condition evaluates to FALSE.

The iif() function may be used in VBA or in an SQL query. The value returned can be a text string, a number or a True/False literal value.

An Excel AND() function can be converted to Access like this:

=AND(expression1, expression2)
becomes
iif(expression1 AND expression2, True)

Examples

Dim strLocal as String
Dim strDemo as String

strLocal = iif ([State] = "TX", "Local", "National")

strDemo = iif ([State] = "TX" OR [State] = "OK" , "Free Delivery ", "")
MsgBox strDemo
strDemo = iif ([State] = "TX" AND [Price] > 20 , "Free", "Delivery $8 surcharge")

“The test of a good teacher is not how many questions he can ask his pupils that they will answer readily, but how many questions he inspires them to ask him which he finds it hard to answer” ~ Alice Wellington Rollins

Related:

If Then Else - If-Then-Else
Case - If Then Else
Nz - Detect a NULL value


© Copyright SS64.com 1999-2013
Some rights reserved