DoCmd.SetFilter method (Access)
Use the SetFilter method to apply a filter to the records in the active datasheet, form, report, or table.
Syntax
expression.SetFilter (FilterName, WhereCondition, ControlName)
expression A variable that represents a DoCmd object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
FilterName | Optional | Variant | If provided, the name of a query or of a filter saved as a query. This argument or the WhereCondition argument is required. |
WhereCondition | Optional | Variant | If provided, a SQL WHERE clause that restricts the records in the datasheet, form, report, or table. |
ControlName | Optional | Variant | If provided, the name of the control that corresponds to the subform or subreport to be filtered. If empty, the current object is filtered. |
Remarks
When you run this method, the filter is applied to the table, form, report or datasheet (for example, query result) that is active and has the focus.
The Filter property of the active object is used to save the WhereCondition argument 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 are not automatically applied.
To automatically apply a filter when the object is opened, set the FilterOnLoad property to True.
Example
The following code example filters the active object so that it displays only records that begin with "NWTB".
DoCmd.SetFilter WhereCondition:="[Product Code] Like ""NWTB*"""
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기