Filter Event — Event Procedures Example
The following example shows how to disable the TotalDue control on an Orders form when the user tries to create a filter, so that the user can't filter on this field. Any records that have a TotalDue value and meet the other filter criteria will always be shown on the filtered form. This example also forces the user to use the Filter By Form window and not the Advanced Filter/Sort window.
To try this example, add the following event procedure to an Orders form that contains a TotalDue control. Try to create a filter by using the Advanced Filter/Sort window that uses the TotalDue control. Also try creating the same filter by using the Filter By Form window.
Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)
If FilterType = acFilterByForm Then
Forms!Orders!TotalDue.Enabled = False
ElseIf FilterType = acFilterAdvanced Then
MsgBox "The best way to filter this form is to use the " _
& "Filter By Form command or toolbar button.", vbOKOnly + vbInformation
Cancel = True
End If
End Sub