ACC: Query with Expression on Expression Prompts for Parameter

Last reviewed: May 28, 1997
Article ID: Q119755
The information in this article applies to:
  • Microsoft Access versions 1.1, 2.0, 7.0, 97

SYMPTOMS

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

When you run a query, Microsoft Access prompts you to enter a parameter value even though you have not defined a parameter in the query.

CAUSE

This behavior can occur if you create a calculated field with an expression based on another expression on the query and this field has a sort order or criteria. Microsoft Access supports referencing column aliases only in other field cells.

This can be seen most easily in the query's SQL view. The Select list can include expression names, but other clauses, such as Where and Order By, cannot.

RESOLUTION

There are two ways to work around this behavior:

  • Substitute the first expression for the first expression's name in the second expression.
  • Create a second query based on the initial query and include the sort order and criteria in the second query.

Please see the "Steps to Reproduce Behavior" section of this article for examples of these two methods.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb (or NWIND.MDB in versions 1.1 and 2.0), and create a new query based on the Order Details table.

  2. Drag the Quantity field from the field list to the query grid.

  3. Add the following expressions to the query:

          Field: Calc: 5*[Quantity]
          Field: Total: [Calc]+20
    

    (Note that the second expression is based on the first expression.)

  4. Run the query. Note that the query runs correctly.

  5. View the query in Design view again.

  6. Set the Total column's sort order to Ascending.

  7. Run the query again. Note that you are prompted to enter a parameter value even though no parameter is defined in the query.

The SQL statement for this query is:

   SELECT DISTINCTROW [Order Details].Quantity, 5*[quantity] AS Calc,
   [Calc]+20 AS Total
   FROM [Order Details]
   ORDER BY [Calc]+20;

Note that the Order By clause includes the Calc expression, which is not allowed.

To correct the sample query above, use either of the following methods:

  • Change the Total expression in step 3 to be:

          Total: (5*[Quantity])+20
    

    This change substitutes the first expression for the first expression's name in the second expression.

  • Save the sample query after step 4, and then create a new query based on the sample query to include the sort order for the Total expression.

REFERENCES

For more information about calculated fields in queries, search the Help Index for "Calculated fields," or ask the Microsoft Access 97 Office Assistant.


Keywords : kbusage QryParm
Version : 1.10 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : kbworkaround


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: May 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.