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.
- Start Microsoft Access and open the sample database Northwind.mdb.
- Open the Employees form in Design view.
- Set the OnApplyFilter property to the following event procedure:
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As _
Integer)
Me.TimerInterval = 100
End Sub
- 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
- Save the form and open it in Form view.
- On the Records menu, point to Filter, and then click Filter By Form.
- In the First Name box, select Laura.
- On the Filter menu, click Apply Filter/Sort. Note that the record for "Laura Callahan" is returned.
- On the Records menu, point to Filter, and then click Filter By Form.
- In the First Name box, type Test.
- On the Filter menu, click Apply Filter/Sort.
- 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.