Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

Summary

You may receive unexpected results when you use the IIf() (Immediate If) function to evaluate an expression. Your results depend on the use of double quotation marks in the function's arguments.

↑ Back to the top


More information

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.

↑ Back to the top


References

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.

↑ Back to the top


Keywords: KB209192, kbusage, kbhowto

↑ Back to the top

Article Info
Article ID : 209192
Revision : 2
Created on : 6/28/2004
Published on : 6/28/2004
Exists online : False
Views : 238