ACC2000: Error Applying Filter If the Form's Recordset Property Is Set Programmatically (225980)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q225980
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).

SYMPTOMS

When you try to apply a filter to a form, you may receive the following error message:
Cannot apply Filter on one or more fields specified in the Filter property.
When you click OK, you receive the following error message:
An unknown error has occurred.
When you click OK again, you see that no filter is applied.

CAUSE

You are setting the Recordset property for a form programmatically, and you tried to apply a filter to the form.

RESOLUTION

If you plan to use a filter on a form, do not set the Recordset property of the form programmatically. Instead, base the form on a query or a table.

STATUS

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

MORE INFORMATION

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.

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.
  2. Create a new form with the following properties:
       Form: Test1
       -----------------
       Caption: TestForm
    
       Text Box
       -----------------------
       Name: LastName
       ControlSource: LastName
    
       Combo box
       ------------------------
       Name: ReportsTo
       ControlSource: ReportsTo
    					
  3. Set the OnOpen property of the form to the following event procedure:
    Private Sub Form_Open(Cancel As Integer)
    
       Dim rst As ADODB.Recordset
    
       Set rst = New ADODB.Recordset
    
       rst.Open "Employees", CurrentProject.Connection, _
         adOpenKeyset, adLockBatchOptimistic
        
       Set Me.Recordset = rst
    
    End Sub
    					
  4. View the form in Form view.
  5. Right-click the ReportsTo combo box, and then click Filter By Selection.

    Note that you receive the error messages mentioned in the "Symptoms" section of this article.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kberrmsg kbpending KB225980