ACC: How to Use "<", ">", and "=" Operators in Query Parameter

Last reviewed: April 2, 1997
Article ID: Q96463
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

Novice: Requires knowledge of the user interface on single-user computers.

This article describes a simple, non-programmatic way to enable a user to type the comparison operators "<", ">", and "=" in query parameters. It's best to keep the query criteria as simple as possible. For more complex criteria, you must use Visual Basic or Access Basic code.

MORE INFORMATION

  1. Create the following new table and save it as Names:

          Table: Names
          ----------------------
          Field Name: First Name
    
             Data Type: Text
          Field Name: Last Name
             Data Type: Text
          Field Name: Age
             Data Type: Number
             Field Size: Single
    
    

  2. Open the table in Datasheet view and enter the following data:

          First Name   Last Name   Age
          ----------------------------
          Tom          Smith        35
          Anne         Howard        7
          Jim          Bowie        20
          Sue          Thomas       44
    
    

  3. Create the following new query based on the Names table:

          Query: List Names
          --------------------------------------------
          Type: Select Query
    

          Field: First Name
    
             Table: Names
          Field: Last Name
             Table: Names
          Field: Age
             Table: Names
             First Criteria Line: =Mid([Enter Age],2)
             Second Criteria Line: <Mid([Enter Age],2)
             Third Criteria Line: >Mid([Enter Age],2)
             Fourth Criteria Line: <leave blank>
             Show: True
          Field: Expr1:Left([Enter Age],1)
             First Criteria Line: "="
             Second Criteria Line: "<"
             Third Criteria Line: ">"
             Fourth Criteria Line: Is Null
             Show: False
    
       Type the criteria on successive lines (that is, type the First Criteria
       Line criteria on the Criteria line, the Second Criteria Line criteria
       on the Or line, and the Third and Fourth Criteria Line criteria on the
       blank lines below that).
    
    

  4. Save the query and run it. Following is sample output for each of the four types of input:

          [Enter Age]     Output
          ------------------------------------------
          <leave blank>   Tom          Smith      35
                          Anne         Howard      7
                          Jim          Bowie      20
                          Sue          Thomas     44
    
          <21             Anne         Howard      7
                          Jim          Bowie      20
    
          >21             Tom          Smith      35
                          Sue          Thomas     44
    
          =7              Anne         Howard      7
    
       NOTE: The query is not designed to allow combinations of "<", ">", and
       "=", such as ">=20". You must always use one of the three operators,
       no more, no less, or you must leave the whole parameter blank.
    
    
Following is the SQL statement for the query:

   SELECT DISTINCTROW
      [First Name], [Last Name], Age
   FROM
      Names
   WHERE
      (Age=Mid([Enter Age],2) AND Left([Enter Age],1)="=")
   OR
      (Age<Mid([Enter Age],2) AND Left([Enter Age],1)="<")
   OR
      (Age>Mid([Enter Age],2) AND Left([Enter Age],1)=">")
   OR
      (Left([Enter Age],1) Is Null)


Additional query words: greater less than
Keywords : kbusage QryParm
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.