Microsoft KB Archive/279028

= ACC2000: Error with Requery Macro Action to Requery a Control on a Subform =

Article ID: 279028

Article Last Modified on 6/25/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q279028



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SYMPTOMS
When you use the Requery action in a Microsoft Access macro to requery a control on a subform, you receive the following error message:

You can't use the ApplyFilter action on this window.
 * You tried to use the ApplyFilter action or method, but you didn't apply the filter to a table, query, form, or report.
 * You may have applied the filter to a form, but the form wasn't open in Form or Datasheet view.
 * You may have applied the filter to a report but didn't use the ApplyFilter action in a macro specified by the OnOpen property setting.

Use the SelectObject action or method to select the table, query, form, or report before applying the filter.



RESOLUTION
To resolve this behavior, use one of the following methods.

Method 1: Use the RunCommand Macro Action Instead of the Requery Action

 * 1) Open the macro in Design View.
 * 2) Change the Requery action to RunCommand.
 * 3) Set the Command action argument to Run.
 * 4) Close the macro, and then click Yes when you are prompted to save the changes.

Method 2: Use Visual Basic for Applications Code to Requery the Control on the Subform
 Remove the call that is made to the macro. For example, if you have a command button that calls the macro from its OnClick property, remove this macro name from the OnClick property. Add Visual Basic for Applications code to requery the control on the subform. For example, if you are using a command button to requery the subform, click the Build button (the button with the three dots) next to the OnClick property of the command button, click Code Builder, and then click OK.  Enter the following code for the button's Click procedure Forms!!.Form!.SetFocus Me.Requery where  is the name of the main form,  is the name of the subform object that appears on the main form, and  is the name of the control on the subform. </li> On the Debug menu, click Compile , and then close the Visual Basic Editor to return and run your form.</li></ol>

<div class="moreinformation_section">

Steps to Reproduce the Behavior
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

<ol> Open the sample database Northwind.mdb.</li> In the Database Window, click Macros under Objects, and then click New.</li> In the Action column, click Requery. Note that only one argument appears under Action Arguments: Control Name.</li>  For the Control Name argument, enter either of the following expressions: Forms!Orders![Orders Subform].Form!ProductID or Me!ProductID </li> Close the macro, click Yes when you are prompted to save the changes, and save the macro as mcrRequery.</li> In the Database Window, click Forms under Objects, right-click the Orders Subform, and then click Design View.</li> On the View menu, click Properties, and when the property sheet opens, click the All tab.</li> Set the Default View property to Single Form.</li> In the form footer of this form, add a command button.</li> View the properties of this command button, and then set the Caption property to Requery, and set the OnClick property to the macro name mcrRequery.</li> Close the subform, and click Yes when you are prompted to save the changes.</li> Double-click the Orders main form, and then click the Requery button. Note that you receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">