You are currently offline, waiting for your internet to reconnect

ACC2000: How to Use the IIf() (Immediate If) Function

This article was previously published under Q209192
Novice: Requires knowledge of the user interface on single-user computers.

This article applies only to a Microsoft Access database (.mdb).

You may receive unexpected results when you use the IIf() (ImmediateIf) function to evaluate an expression. Your results depend on the use of double quotation marks in the function's arguments.
To illustrate how the use of double quotation marks in the IIf() function's arguments can affect the results, follow these steps:
  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Create the following new query based on the Orders table:
    Query: Test
    Field Name: Sum(IIf("[Freight]>50",1,0))
  3. Run the query. The result is the total number of records in the table, not the number of records with freight charges greater than 50.
  4. View the query in Design view. Remove the double quotation marks so that the query matches the following:
    Query: Test
    Field Name: Sum(IIf([Freight]>50,1,0))
  5. Run the query again. The result is the correct number of records where the freight charge amount is greater than 50.
The double quotation marks in the "[Freight] > 50" expression cause Microsoft Access to evaluate the expression as a string instead of as a comparison. A string always evaluates to True, whereas a comparison tests for the condition to be met before returning a value.
For more information about the IIf function, click Microsoft Access Help on the Help menu, type iif function example in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Article ID: 209192 - Last Review: 06/28/2004 18:32:00 - Revision: 2.0

  • Microsoft Access 2000 Standard Edition
  • kbhowto kbusage KB209192