Filter Event
See Also
Macros
Event Procedures
Applies To
The Filter event can occur within a Microsoft Access project (.adp) or Access database (.mdb).
Within an Access database, a Filter event occurs when the user does one of the following:
- On the Records menu in Form view, points to Filter and then clicks Filter By Form, or clicks Filter By Form on the toolbar. This opens the Filter By Form window, where you can create a filter based on the fields in the form.
- On the Records menu in Form view, points to Filter and then clicks Advanced Filter/Sort. This opens the Advanced Filter/Sort window, where you can create complex filters for the form.
- Clicks Advanced Filter/Sort on the Filter menu while the Filter By Form window is open, or clicks Filter By Form on the Filter menu while the Advanced Filter/Sort window is open. This causes the ApplyFilter event to occur when the open filter window is closed, and then the Filter event to occur when the other filter window is opened.
Within an Access project, a Filter event occurs when the user does one of the following:
- On the Records menu in Form view, points to Filter and then clicks Filter By Form, or clicks Filter By Form on the toolbar. This opens the Filter By Form window, where you can create a filter based on the fields in the form.
- On the Records menu in Form view, points to Filter and then clicks Server Filter By Form on the toolbar. This opens the Server Filter By Form window, where you can quickly create a server filter based on the fields in the form.
- The Advanced Filter/Sort window is not available in an Access project.
Remarks
To run a macro or event procedure when this event occurs, set the OnFilter property to the name of the macro or to [Event Procedure].
You can use the Filter event to:
- Remove any previous filter for the form. To do this, set the Filter or ServerFilter property of the form to a zero-length string (" ") in the Filter macro or event procedure. This is especially useful if you want to make sure extraneous criteria don't appear in the new filter. For example, when you use the Filter By Selection feature, the criteria you use (the selected text in the form) is added to the Filter or ServerFilter property WHERE clause expression, and appears in both the Filter By Form window and the Advanced Filter/Sort window or the Server Filter By Form window. You can remove these old criteria by using the Filter event.
- Enter default settings for the new filter. To do this, set the Filter or ServerFilter property to include these criteria. For example, you may want all filters for a Products form to display only current products (products for which the Discontinued control in the Products form isn't selected).
- Use your own custom filter window instead of one of the Microsoft Access filter windows. When the Filter event occurs, you can open your own custom form and use the entries on this form to set the Filter or ServerFilter property and filter the original form. When the user closes this custom form, set the FilterOn or ServerFilterByForm property of the original form to True (–1) to apply the filter. Canceling the Filter event prevents the Microsoft Access filter window from opening.
- Prevent certain controls on the form from appearing or being used in the Filter By Form or Server Filter By Form window. If you hide or disable a control in the Filter macro or event procedure, the control is hidden or disabled in the Filter By Form or Server Filter By Form window, and can't be used to set filter criteria. You can then use the ApplyFilter event to show or enable this control after the filter is applied, or when the filter is removed from the form.