Table of contents
TOC
折叠目录
展开目录

Form.Filter 事件 (访问)Form.Filter Event (Access)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

当用户通过单击按窗体筛选高级筛选/排序按窗体服务器筛选打开筛选窗口时发生。Occurs when the user opens a filter window by clicking Filter by Form, Advanced Filter/Sort, or Server Filter By Form.

语法Syntax

表达式筛选器(* 取消 * FilterType ** )expression. Filter( ** Cancel, ** FilterType )

表达式_一个表示窗体对象的变量。_expression A variable that represents a Form object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
CancelCancel必需RequiredIntegerInteger该设置确定是否打开筛选窗口。将 Cancel 参数设置为True (?1) 可防止打开筛选窗口。您还可以使用CancelEventDoCmd对象的方法可取消打开筛选窗口。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.
FilterTypeFilterType必需RequiredIntegerInteger[过滤] 窗口用户试图打开。FilterType 参数可以是下列固有常量之一:The filter window the user is trying to open. The FilterType argument can be one of the following intrinsic constants:
  • acFilterByFormacFilterByForm
  • acFilterAdvancedacFilterAdvanced
  • acServerFilterByFormacServerFilterByForm

注解Remarks

若要此事件发生时运行宏或事件过程,请将OnFilter属性设为宏的名称或 [事件过程]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:

  • 删除所有以前筛选的窗体。若要执行此操作,将窗体的FilterServerFilter属性设置为零长度字符串 ("") 在Filter宏或事件过程。这是特别有用如果您想要确保在新的筛选中不显示无关的条件。例如,当使用按选定内容筛选功能,则使用 (在窗体中选取的文本) 的条件将添加到FilterServerFilter属性 WHERE 子句表达式中,和按窗体筛选窗口中显示与高级筛选/排序窗口或按窗体服务器筛选窗口中。通过使用筛选器事件,您可以删除这些旧标准。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.

  • 输入新筛选器的默认设置。若要执行此操作,设置FilterServerFilter属性,以包括这些条件。例如,您可以仅显示当前产品 (产品的停产控件在产品窗体中未选中) 产品窗体的所有筛选器。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).

  • 使用您自己的自定义筛选器窗口而不是一个 Microsoft Access 筛选器窗口。筛选器事件发生时,可以打开自定义窗体,并在此窗体上使用的项,以设置FilterServerFilter属性和筛选器的原始表单。当用户关闭此自定义窗体时,设置原始窗体的开启筛选属性为,则返回 True (?1) 可应用的筛选器。取消筛选器事件禁止 Microsoft Access 筛选器窗口打开。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.

  • 防止显示或在按窗体筛选按窗体服务器筛选窗口中使用窗体上的某些控件。控件如果您隐藏或禁用的控件在Filter宏或事件过程中,隐藏或禁用在按窗体筛选按窗体服务器筛选窗口中,并且不能用于设置筛选条件。然后,可以使用ApplyFilter事件来显示或启用该控件在应用筛选器之后,或者当从窗体中删除筛选器。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.

示例Example

下面的示例演示如何禁用订单窗体上的 totaldue 控件,当用户试图创建筛选器,以便用户不能对此域进行筛选。任何含有 TotalDue 值并且满足其他筛选条件的记录将始终显示在筛选的窗体上。此示例还强制用户使用按窗体筛选窗口而不是高级筛选/排序窗口。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.

要试验此示例,请将下列事件过程添加含有 TotalDue 控件的订单窗体。请尝试使用高级筛选/排序窗口使用 totaldue 控件创建筛选器。请尝试使用按窗体筛选窗口中创建相同的筛选器。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

另请参阅See also

概念Concepts

窗体对象Form Object

© 2018 Microsoft