Microsoft KB Archive/106288: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - ">" to ">")
 
(One intermediate revision by the same user not shown)
Line 68: Line 68:
<pre class="fixed_text">      Query: Test
<pre class="fixed_text">      Query: Test
       ---------------------------------------
       ---------------------------------------
       Field Name: Sum(IIf(&quot;[Freight]&gt;50&quot;,1,0))
       Field Name: Sum(IIf("[Freight]>50",1,0))
                         </pre></li>
                         </pre></li>
<li>Run the query. The result will be the total number of records in the table, not the number of records with Freight charges greater than 50.</li>
<li>Run the query. The result will be the total number of records in the table, not the number of records with Freight charges greater than 50.</li>
Line 75: Line 75:
<pre class="fixed_text">      Query: Test
<pre class="fixed_text">      Query: Test
       -------------------------------------
       -------------------------------------
       Field Name: Sum(IIf([Freight]&gt;50,1,0))
       Field Name: Sum(IIf([Freight]>50,1,0))
                         </pre></li>
                         </pre></li>
<li>Run the query again. The result will be the correct number of records where the freight charge amount is greater than 50.</li></ol>
<li>Run the query again. The result will be the correct number of records where the freight charge amount is greater than 50.</li></ol>


The double quotation marks around the &quot;[Freight] &gt; 50&quot; argument cause Microsoft Access to evaluate the expression as a string instead of as a comparison. A string will always evaluate to true, while a comparison will test for the condition to be met before returning a value.
The double quotation marks around the "[Freight] > 50" argument cause Microsoft Access to evaluate the expression as a string instead of as a comparison. A string will always evaluate to true, while a comparison will test for the condition to be met before returning a value.


</div>
</div>
Line 86: Line 86:
== REFERENCES ==
== REFERENCES ==


For more information about the IIf function, search for &quot;IIf function,&quot; and then &quot;IIf Function&quot; using the Microsoft Access 97 Help Index.
For more information about the IIf function, search for "IIf function," and then "IIf Function" using the Microsoft Access 97 Help Index.


</div>
</div>

Latest revision as of 17:49, 20 July 2020

Knowledge Base


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

Article ID: 106288

Article Last Modified on 1/18/2007



APPLIES TO

  • Microsoft Access 1.0 Standard Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition



This article was previously published under Q106288

Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

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

MORE INFORMATION

The following example demonstrates how the use of double quotation marks in the IIf() function's arguments can affect the results:

  1. Open the sample database Northwind.mdb (or NWIND.MDB in version 1.x or 2.0)
  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 will be 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 the query matches the following:

          Query: Test
          -------------------------------------
          Field Name: Sum(IIf([Freight]>50,1,0))
                            
  5. Run the query again. The result will be the correct number of records where the freight charge amount is greater than 50.

The double quotation marks around the "[Freight] > 50" argument cause Microsoft Access to evaluate the expression as a string instead of as a comparison. A string will always evaluate to true, while a comparison will test for the condition to be met before returning a value.

REFERENCES

For more information about the IIf function, search for "IIf function," and then "IIf Function" using the Microsoft Access 97 Help Index.

Keywords: kbhowto kbusage KB106288