Form 属性 (权限)Form.Filter property (Access)

当筛选器应用于窗体、报表、查询或表时, 可以使用Filter属性来指定要显示的记录子集。You can use the Filter property to specify a subset of records to be displayed when a filter is applied to a form, report, query, or table. 读/写 StringRead/write String.



expression:表示 Form 对象的变量。expression A variable that represents a Form object.


如果您想要指定 Microsoft Access 项目 (.adp) 中的服务器筛选数据的服务器上,使用 服务器过滤器 属性。If you want to specify a server filter within a Microsoft Access project (.adp) for data located on a server, use the ServerFilter property.

Filter 属性是一个字符串表达式,由不带 WHERE 关键字的 WHERE 子句组成。The Filter property is a string expression consisting of a WHERE clause without the WHERE keyword. 例如, 下面的 Visual Basic 代码定义并应用筛选器, 以便仅显示来自美国的客户。For example, the following Visual Basic code defines and applies a filter to show only customers from the USA.

Me.Filter = "Country = 'USA'" 
Me.FilterOn = True


设置Filter属性不会影响 ADO Filter属性。Setting the Filter property has no effect on the ADO Filter property.

可以使用 Filter 属性保存筛选器,以供日后应用。You can use the Filter property to save a filter and apply it at a later time. 筛选器随其中创建有它们的对象一起保存。Filters are saved with the objects in which they are created. 当打开该对象时,它们将自动加载,但不会自动应用。They are automatically loaded when the object is opened, but they aren't automatically applied.

创建新对象时, 它会继承创建它的表或查询的RecordSourceFilterOrderByOrderByOn属性。When a new object is created, it inherits the RecordSource, Filter, OrderBy, and OrderByOn properties of the table or query that it was created from.

若要将已保存的筛选器应用于窗体、查询或表, 可以在工具栏上选择 "应用筛选", 选择 "记录" 菜单上的 "应用筛选/排序", 或者使用宏或 Visual Basic 将 "开启筛选" 属性设置为TrueTo apply a saved filter to a form, query, or table, you can choose Apply Filter on the toolbar, choose Apply Filter/Sort on the Records menu, or use a macro or Visual Basic to set the FilterOn property to True. 对于报表,可以在报表的属性表中通过将 FilterOn 属性设置为 YES 来应用筛选器。For reports, you can apply a filter by setting the FilterOn property to Yes in the report's property sheet.

“应用筛选”**** 按钮指示 FilterFilterOn 属性的状态。The Apply Filter button indicates the state of the Filter and FilterOn properties. 应用筛选之前,该按钮始终处于禁用状态。The button remains disabled until there is a filter to apply. 如果当前已应用了一个现有筛选器,应用筛选按钮将显示为按下状态。If an existing filter is currently applied, the Apply Filter button appears pressed in.

当窗体打开时自动应用筛选器,指定的窗体,或者可以使用 ApplyFilter 操作的宏或事件过程,可以使用 ApplyFilter DoCmd 对象的方法的 OnOpen 事件属性设置中。To apply a filter automatically when a form is opened, specify in the OnOpen event property setting of the form either a macro that uses the ApplyFilter action or an event procedure that uses the ApplyFilter method of the DoCmd object.

您可以通过选择 "按下" "应用筛选" 按钮、选择 "记录" 菜单上的 "取消筛选/排序" 或使用 Visual Basic 将 "开启筛选" 属性设置为False来删除筛选。You can remove a filter by choosing the pressed-in Apply Filter button, choosing Remove Filter/Sort on the Records menu, or using Visual Basic to set the FilterOn property to False.

如果窗体设计视图中设置有 Filter 属性,则 Microsoft Access 不会尝试验证 SQL 表达式。When the Filter property is set in form Design view, Microsoft Access does not attempt to validate the SQL expression. 如果 SQL 表达式无效,则当应用筛选时会发生错误。If the SQL expression is invalid, an error occurs when the filter is applied.

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.