ACC2000: Error with Requery Macro Action to Requery a Control on a Subform (279028)



The information in this article applies to:

  • Microsoft Access 2000

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

  1. 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.
  2. 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.
  3. Enter the following code for the button's Click procedure
    Forms!<FormName>!<SubformControl>.Form!<ControlName>.SetFocus
    Me.Requery
    						
    where <FormName> is the name of the main form, <SubformControl> is the name of the subform object that appears on the main form, and <ControlName> is the name of the control on the subform.
  4. On the Debug menu, click Compile <name>, and then close the Visual Basic Editor to return and run your form.

MORE INFORMATION

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.

  1. Open the sample database Northwind.mdb.
  2. In the Database Window, click Macros under Objects, and then click New.
  3. In the Action column, click Requery. Note that only one argument appears under Action Arguments: Control Name.
  4. For the Control Name argument, enter either of the following expressions:
    Forms!Orders![Orders Subform].Form!ProductID
    						
    or
    Me!ProductID
    						
  5. Close the macro, click Yes when you are prompted to save the changes, and save the macro as mcrRequery.
  6. In the Database Window, click Forms under Objects, right-click the Orders Subform, and then click Design View.
  7. On the View menu, click Properties, and when the property sheet opens, click the All tab.
  8. Set the Default View property to Single Form.
  9. In the form footer of this form, add a command button.
  10. 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.
  11. Close the subform, and click Yes when you are prompted to save the changes.
  12. Double-click the Orders main form, and then click the Requery button. Note that you receive the error message that is mentioned in the "Symptoms" section of this article.

REFERENCES

For more information about the RunCommand macro action, click Microsoft Access Help on the Help menu, type runcommand in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

For more information about getting help on Visual Basic for Applications, click Microsoft Visual Basic Help on the Help menu, type vba in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

For more information about the SetFocus method, click Microsoft Visual Basic Help on the Help menu, type setfocus in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

For more information about the Requery method, click Microsoft Visual Basic Help on the Help menu, type requery in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:6/25/2004
Keywords:kbbug kbpending KB279028