Microsoft KB Archive/209192

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

Article ID: 209192

Article Last Modified on 6/28/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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).



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.



MORE INFORMATION
To illustrate how the use of double quotation marks in the IIf function's arguments can affect the results, follow these steps:  Start Microsoft Access and open the sample database Northwind.mdb. Create the following new query based on the Orders table:

Query: Test

---

Field Name: Sum(IIf("[Freight]>50",1,0))

 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. 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))

 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.

<div class="references_section">