ApplyFilter Event

Applies To

Form.

Description

The ApplyFilter event occurs when the user does one of the following:

  • Clicks the Apply Filter/Sort command on the Filter menu, or clicks the Apply Filter button on the toolbar. This applies the most recently created filter (created using either the Filter By Form feature or the Advanced Filter/Sort window).
  • Clicks the Filter By Selection subcommand of the Filter command on the Records menu, or clicks the Filter By Selection button on the toolbar. This applies a filter based on the current selection in the form.
  • Clicks the Remove Filter/Sort command on the Records menu, or clicks the Remove Filter button on the toolbar. This removes any filter (or sort) currently applied to the form.
  • Closes the Advanced Filter/Sort window or the Filter By Form window.

Remarks

You can use the ApplyFilter event to:

  • Make sure the filter that is being applied is correct. For example, you may want to be sure that any filter applied to an Orders form includes criteria restricting the OrderDate field. To do this, check the value of the Filter property for the form to make sure this criteria is included in the WHERE clause expression in this property.
  • Change the display of the form before the filter is applied. For example, when you apply a certain filter, you may want to disable or hide some fields that are not appropriate for the records displayed by this filter.
  • Undo or change actions you took when the Filter event occurred. For example, you can disable or hide some controls on the form when the user is creating the filter, because you do not want these controls to be included in the filter criteria. You can then enable or show these controls after the filter is applied.

The actions in the ApplyFilter macro or event procedure occur before the filter is applied or removed; or after the Advanced Filter/Sort or Filter By Form window is closed, but before the form is redisplayed. The criteria you’ve entered in the newly created filter are available to the ApplyFilter macro or event procedure (as the setting of the Filter property).

Note The ApplyFilter event does not occur when you apply or remove a filter using the ApplyFilter, OpenForm, or ShowAllRecords actions in a macro, or their corresponding methods of the DoCmd object in Visual Basic. It also does not occur if you use the Close action or the Close method of the DoCmd object to close the Advanced Filter/Sort window or the Filter By Form window. The ApplyFilter event also does not occur if you set the Filter property or FilterOn property in a macro or Visual Basic (although you can set these properties in an ApplyFilter macro or event procedure).

See Also

Filter Property, FilterLookup Property, FilterOn Property, OrderBy Property, OrderByOn Property.