ACC2002: Access Crashes When You Set IsFilterOn Property in DataPageComplete Event (296491)



The information in this article applies to:

  • Microsoft Access 2002

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:

<SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(oEventInfo)>

The <I>oEventInfo</I> 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 = ""  then
		MSODSC.RecordsetDefs(0).ServerFilter = "Country = 'UK'" 
	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>
<!--
	' Set the Filter criteria.
	MSODSC.DataPages(0).Filter = "Country = 'UK'"
	
	If MSODSC.DataPages(0).IsFilterOn then
		' If the filter is on, turn it off.
		MSODSC.DataPages(0).IsFilterOn = false
	else
		' Otherwise, turn it back on.
		MSODSC.DataPages(0).IsFilterOn = true
	end if
-->
</SCRIPT>
				

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 Pages under Objects, and then click New.
  3. 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.
  4. Save the data access page.
  5. On the Tools menu, point to Macro, and then click Microsoft Script Editor.
  6. In the Client Objects & Events box, click MSODSC. In the list of events, click DataPageComplete.
  7. Add the following script to the DataPageComplete event:
             MSODSC.DataPages(0).Filter = "Country='UK'"
             MSODSC.DataPages(0).IsFilterOn = True
        
    					
  8. Save the page and then view it in Access or in Internet Explorer 5 or later.
Note that you see one of the behaviors that is described in the "Symptoms" section of this article.

Modification Type:MajorLast Reviewed:9/25/2003
Keywords:kberrmsg kbprb KB296491