ACC2000: When You Sort Parameter Query Results You Are Prompted for Parameters Again

ID: Q245467


The information in this article applies to:
  • Microsoft Access 2000

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

This article applies only to a Microsoft Access database (.mdb).


SYMPTOMS

In Access 2000, each time that you sort a query that has parameters, the query prompts you for the parameters again. This behavior does not occur in Access 97.


RESOLUTION

You can create a form to hold the parameters, and then have the query refer to that form. To see how this works, follow these steps:

  1. Open the sample database Northwind.mdb.


  2. In the Database window, click Queries, and then click New.


  3. In the New Query dialog box, click Design, and then click OK.


  4. In the Show Table dialog box, click the Orders table, and then click OK.


  5. Add the following fields to the query design grid:


  6. 
       Field: OrderID
       Table: Orders
    
       Field: CustomerID
       Table: Orders
    
       Field: OrderDate
       Table: Orders
       Criteria: Is Not Null And Between [Forms]![frmOrdersByDate]![StartDate]
                 And [Forms]![frmOrdersByDate]![EndDate] 
  7. On the Query menu, click Parameters.


  8. Type the following parameters, and select the following data types:


  9. Parameter Data type
    [Forms]![frmOrdersByDate]![StartDate] Date/Time
    [Forms]![frmOrdersByDate]![EndDate] Date/Time
  10. Save the query as OrdersByDate, and then close it.


  11. Create the following new form:


  12. 
       Form: frmOrdersByDate
       ---------------------
       Caption: TestForm
    
       Command button
       ---------------------
       Name: Button0
       Caption: Show Records
    
       TextBox
       ---------------
       Name: StartDate
    
       TextBox
       ------------------------------
       Name: EndDate
     
  13. Set the OnClick property of the command button to the following event procedure:


  14. 
    Private Sub OK_Click()
       DoCmd.OpenQuery "OrdersByDate"
    End Sub 
  15. Save the form as frmOrdersByDate, and then open the form in Form view.


  16. For the parameters, enter the following:


  17. 
       StartDate: 1/1/1997
       EndDate:   12/31/1997 
  18. Click the Show Records button. The query results are displayed.


  19. On the Records menu, point to Sort, and then click Sort Ascending.


Note that the data is sorted, and that you are not prompted for the parameters again.


STATUS


MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.


  2. Run the "Sales by Year" query.


  3. For the parameters, enter the following:
    
       StartDate: 1/1/1997
       EndDate:   12/31/1997 
    The query results are displayed.


  4. On the Records menu, point to Sort, and then click Sort Ascending.


Note that you are prompted for the parameters again.

Additional query words: prb

Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: January 17, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.