To create an event procedure that runs when the ApplyFilter event occurs, set the OnApplyFilter property to [Event Procedure], and click the Build button .
Syntax
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
The ApplyFilter event procedure has the following arguments.
Argument | Description | |
---|---|---|
Cancel | The setting determines whether to apply the filter. Setting the Cancel argument to True (–1) prevents the filter from being applied. You can also use the CancelEvent method of the DoCmd object to cancel applying the filter. | |
ApplyType | The action you took that caused the ApplyFilter event to occur. The ApplyType argument can be one of the following intrinsic constants: | |
Constant | Value | |
acShowAllRecords | 0 | |
acApplyFilter | 1 | |
acCloseFilterWindow | 2 | |
acApplyServerFilter | 3 | |
acCloseServerFilterWindow | 4 |
Remarks
You can use the ApplyFilter event procedure to show or hide, enable or disable certain controls on the form when the filter is applied or removed. For example, when a filter is applied to an Orders form to show only orders that have been paid for, you can hide the AmountDue, Tax, and TotalDue fields when the ApplyType argument is acApplyFilter, and show them again when the ApplyType argument is acShowAllRecords.
You can also use the ApplyFilter event procedure to undo actions you took when the Filter event occurred. This is especially useful if the user closed the filter window without creating a filter when the ApplyType argument is acCloseFilterWindow or acCloseServerFilterWindow.