ACC: Query with Parameters to Evaluate Complex Criteria

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

SUMMARY

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

Microsoft Access allows the use of variable parameters in queries. This article discusses how to construct a query requiring more than one prompt. Each parameter can be used both as criteria and as a field to allow complicated evaluation of the value entered in each parameter.

MORE INFORMATION

The following parameter query is based on the Orders table in the sample database Northwind.mdb (or NWIND.MDB in earlier versions). It selects orders written between two variable dates provided by the user.

If either the Start Date or the End Date is not entered, the query returns all dates greater than or equal to the Start Date, or less than or equal to the End Date. If neither a Start Date nor an End Date is entered, the query returns all orders.

  1. Open the sample database Northwind.mdb (or NWIND.MDB in earlier versions).

  2. Create a new query based on the Orders table.

  3. Enter the following query:

          Query: FindOrdersByDate
          -----------------------------------------------------------
          Field: OrderID
    
             Show: Yes
          Field: OrderDate
             Sort: Ascending
             Show: Yes
             First Criteria Line: Between [Start Date] and [End Date]
             Second Criteria Line: <=[End Date]
             Third Criteria Line: >=[Start Date]
          Field: [Start Date]
             Show: No
             First Criteria Line: Is Not Null
             Second Criteria Line: Is Null
             Third Criteria Line: Is Not Null
             Fourth Criteria Line: Is Null
             Field: [End Date]
             Show: No
             First Criteria Line: Is Not Null
             Second Criteria Line: Is Not Null
             Third Criteria Line: Is Null
             Fourth Criteria Line: Is Null
    
    

  4. On the Query menu, click Parameters. In the Query Parameters box add two entries, one for each parameter in the query, as follows:

          Query Parameters
          -----------------------
          Parameter: Start Date
    
             Data Type: Date/Time
          Parameter: End Date
             Data Type: Date/Time
    
    

  5. To run the query, on the View menu, click Datasheet. Microsoft Access will prompt you for the value of the parameters and will substitute the proper values in the query.

REFERENCES

For more information about these kinds of queries, search the Help Index for "Query by Form," or "Parameter Queries," or ask the Microsoft Access 97 Office Assistant.


Additional query words: queries ui parameter query
Keywords : kbusage QryParm
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


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.