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.