Filter Event - Event Procedures

Filter Event — Event Procedures

See Also         Example

To create an event procedure that runs when the Filter event occurs, set the OnFilter property to [Event Procedure], and click the Build button .

Syntax

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)

The Filter event procedure has the following arguments.

Argument Description
Cancel The setting determines whether to open the filter window. Setting the Cancel argument to True (–1) prevents the filter window from opening. You can also use the CancelEvent method of the DoCmd object to cancel opening the filter window.
FilterType The filter window the user is trying to open. The FilterType argument can be one of the following intrinsic constants:
  Constant Value
  acFilterByForm 0
  acFilterAdvanced 1
  acServerFilterByForm 2

Remarks

You can use the Filter event procedure to disable or hide certain controls in the Filter By Form or Server Filter By Form window, preventing them from being used in filter criteria. For example, you may want your Orders form always to show records that have a value in the TotalDue control, no matter how small. You can disable or hide this control in the Filter event procedure, then enable or show it in the ApplyFilter event procedure. Disabling and hiding controls in the Filter By Form or Server Filter By Form window is best accomplished in the Filter event procedure rather than the Filter macro, because you can check the FilterType argument to see if the user opened the Filter By Form or Server Filter By Form window. In a Microsoft Access database (.mdb), all of the fields in a form appear in the Advanced Filter/Sort window, even if the controls are disabled or hidden.