Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Test a User-Defined Filter Using the Filter By Form Feature


View products that this article applies to.

This article was previously published under Q210037
Moderate: Requires basic macro, coding, and interoperability skills.

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

↑ Back to the top


Summary

This article shows you how to test the validity of a user-defined filter when using the Filter By Form feature of Microsoft Access. The sample procedure demonstrates some of the validation techniques that you can use to ensure that the filter that you apply to the form returns records.

↑ Back to the top


More information

In the following sample procedure, if the filter that you apply does not return any records, a message appears, and you return to the Filter By Form screen to retry the filter.

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. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Open the Employees form in Design view.
  3. Set the OnApplyFilter property to the following event procedure:
    Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As _
       Integer)
       Me.TimerInterval = 100
    End Sub
    					
  4. Set the OnTimer property to the following event procedure:
    Private Sub Form_Timer()
       Dim strfilter As String
       Me.TimerInterval = 0
       If IsNull(Me.Filter) Then Exit Sub
       strfilter = Me.Filter
       If Me.RecordsetClone.RecordCount = 0 Then
           MsgBox "The selected filter:" & Chr(13) & _
           strfilter & Chr(13) & _
           "returns no records. Try a less restrictive search."
           ' Form, Records, Filter, Filter By Form.
           DoCmd.DoMenuItem 0, 5, 0, 0, acMenuVer70
       End If
    End Sub
    					
  5. Save the form and open it in Form view.
  6. On the Records menu, point to Filter, and then click Filter By Form.
  7. In the First Name box, select Laura.
  8. On the Filter menu, click Apply Filter/Sort. Note that the record for "Laura Callahan" is returned.
  9. On the Records menu, point to Filter, and then click Filter By Form.
  10. In the First Name box, type Test.
  11. On the Filter menu, click Apply Filter/Sort.
  12. Note that the following message appears, indicating the filter does not return records:
    The selected filter:
    ((Employees.FirstName="Test"))
    returns no records. Try a less restrictive search.
NOTE: To cancel the Filter By Form mode, remove all criteria and click Apply Filter/Sort on the Filter menu.

↑ Back to the top


References

For more information about filters, click Microsoft Access Help on the Help menu, type filter property in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

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

↑ Back to the top


Keywords: KB210037, kbusage, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 210037
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 396