Microsoft KB Archive/288374

= ACC2002: Problems Using Requery and Refresh Methods During Pivot Events =

Article ID: 288374

Article Last Modified on 11/6/2003

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q288374



Advanced: Requires expert coding, interoperability, and multiuser skills.

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



SYMPTOMS
When you call the Requery or Refresh methods from certain events in a form, one of the following occurs:

 You receive the following error message, and then Microsoft Access shuts down:

Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience.

When you view the details in the error report, the report says that an error occurred in Owc10.dll. Microsoft Access stops responding indefinitely, forcing you to have to press CTRL+ALT+DELETE to end the task.



CAUSE
The Requery or Refresh method causes infinite recursion, or an endless loop, that eventually causes Microsoft Access to quit or to stop responding.



RESOLUTION
Use these methods from a different event that does not cause infinite recursion.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
When you call data-related methods, such as Requery or Refresh, your code can cause infinite recursion, or an endless loop, if the method is called from certain events. This is because the action that the method performs causes the form event to fire repeatedly.

For example, the Query event of a form fires when the PivotTable of a form queries its data source. If you call the Requery or Refresh method from the Query event of a form, the recordsource of the form is requeried (or refreshed). This causes the PivotTable of the form to query its data source a second time, which causes the Query event of the form to fire again. The code in the Query event executes again, which causes the recordsource to be requeried (or refreshed) again. This causes the Query event to fire a third time. This process continues until Microsoft Access quits.

Not all events will cause Microsoft Access to quit with the error message that is mentioned in the &quot;Symptoms&quot; section of this article with the Requery or Refresh methods. If you call these methods from some other events, Access may not respond at all without ever returning an error message. This forces you to have to press CTRL+ALT+DELETE to end the task. You should not call the Requery or Refresh methods from any of the following events in a form:
 * AfterFinalRender
 * AfterRender
 * BeforeQuery
 * BeforeRender
 * CommandBeforeExecute
 * CommandChecked
 * CommandEnabled
 * CommandExecute
 * Current (Even though this is not a Pivot related event, calling these methods will cause Microsoft Access to stop responding.)
 * DataChange
 * DataSetChange
 * OnConnect
 * PivotTableChange
 * Query
 * SelectionChange
 * PivotTableChange

Steps to Reproduce the Behavior
 Open the sample database Northwind.mdb. On the Insert menu, click Form.</li> In the New Form dialog box, click Form Wizard, and then click OK.</li> In the Form wizard, click the arrow in the Tables/Queries box, and then click Tables: Orders in the drop-down list.</li> Add all the fields to the Selected Fields list, and then click Finish. Note that a new form that is based on the Orders table is created in Form view.</li> On the View menu, click Design View.</li> On the View menu, click Code to view the module of the form.</li>  Add the following code to the module of the form: Private Sub Form_Query Me.Requery End Sub </li> On the File menu, click Close and Return to Microsoft Access.</li> On the File menu, click Save.</li> Close the form.</li> Open the form in Form view.</li> On the View menu, click PivotTable View.</li></ol>

Note that you receive the following error message, and then Microsoft Access quits:

Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience.

When you view the details in the error report, the report says that an error occurred in Owc10.dll.

<div class="references_section">