Microsoft KB Archive/296491

= ACC2002: Access Crashes When You Set IsFilterOn Property in DataPageComplete Event =

Article ID: 296491

Article Last Modified on 9/25/2003

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q296491



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 view a data access page in Access 2002, one of the following may occur.  When you view the page in Access, you may receive the following error:

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

After you respond to the error message, Access quits. When you view the page in Access, Access may quit unexpectedly. When you view the page in Microsoft Internet Explorer 5 or later, the page may continually refresh or Internet Explorer may quit unexpectedly.



CAUSE
You have set the IsFilterOn property to True in the DataPageComplete event. Setting this property in the DataPageComplete event causes the event to fire recursively.



RESOLUTION
There are two possible workarounds to this behavior.

Method 1
Use the ServerFilter property instead of IsFilterOn to apply a filter when the page opens. The following sample code shows you how to set the ServerFilter property in the DataPageComplete event.

IMPORTANT: When you create VBScript blocks for MSODSC events, you must add a parameter to the event name as follows:



The oEventInfo parameter returns specific information about the event to the script. You must add this parameter, whether or not it will be used, because the script will not work without it.

<SCRIPT language=vbscript event=DataPageComplete(oEventInfo) for=MSODSC> ' Set the ServerFilter property to a filter criteria string. If MSODSC.RecordsetDefs(0).ServerFilter = &quot;&quot; then MSODSC.RecordsetDefs(0).ServerFilter = &quot;Country = 'UK'&quot; end if </SCRIPT>

Method 2
Use a different event, such as the Click event of a button, to set the IsFilterOn property. The following sample code toggles the value of the IsFilterOn property on or off. <SCRIPT language=vbscript event=onclick for=cmdToggleFilter>

</SCRIPT>

<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 Pages under Objects, and then click New.</li> In the New Data Access Page dialog box, click AutoPage: Columnar, click Customers in the Choose the table or query where the object's data comes from box, and then click OK.</li> Save the data access page.</li> On the Tools menu, point to Macro, and then click Microsoft Script Editor.</li> In the Client Objects & Events box, click MSODSC. In the list of events, click DataPageComplete.</li>  Add the following script to the DataPageComplete event: MSODSC.DataPages(0).Filter = &quot;Country='UK'&quot; MSODSC.DataPages(0).IsFilterOn = True </li> Save the page and then view it in Access or in Internet Explorer 5 or later.</li></ol>

Note that you see one of the behaviors that is described in the &quot;Symptoms&quot; section of this article.

Additional query words: prb

Keywords: kberrmsg kbprb KB296491

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.