Microsoft KB Archive/154421

= ACC95: FilterName Argument of OpenForm Macro Action Does Not Sort =

Article ID: 154421

Article Last Modified on 7/5/2002

-

APPLIES TO


 * Microsoft Access 95 Standard Edition

-



This article was previously published under Q154421



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



SYMPTOMS
When the FilterName argument of an OpenForm action is based on a query or an SQL SELECT Statement that includes the sorting of a field or fields in ascending or descending order, sorting will be ignored when the OpenForm action is executed.



CAUSE
Microsoft Access 7.0 does not automatically set the form's OrderByOn property to True when the FilterName argument of the OpenForm action uses a filter that is sorting by one or more fields.



RESOLUTION
To work around this problem, follow these steps:

 Add a new SetValue action to immediately follow the OpenForm action. Set the Item argument of the SetValue action to

Forms! .OrderByOn

where is the name of the form being opened. Set the Expression argument of the SetValue action to True



STATUS
Microsoft has confirmed this to be a problem in Microsoft Access 7.0. This problem no longer occurs in Microsoft Access 97.



MORE INFORMATION
If the filter has criteria to limit the number of records to be viewed by the form, the form will, in fact, be limited to only those records which meet the criteria's condition; but all sorting, however, will be ignored.

Steps to Reproduce Problem
 Open the sample database Northwind.mdb.</li> Create a new query in Design view.</li> In the Show Table box, add the Customers table to the query and drag all the fields to the QBE grid.</li> Set Sort for the City column to Ascending.</li> Close and save the query as Query1.</li>  Create the following new macro:

<pre class="fixed_text">     Macro Action OpenForm

Action Arguments -        Form Name: Customers View: Form Filter Name: Query1 Where Condition: Data Mode: Edit Window Mode: Normal </li> Save the macro as Macro1.</li> On the Run menu, click Start. Note that the records on the form are not sorted by City as expected.</li></ol>

<div class="references_section">