DoCmd.SetFilter (Access)
Use the SetFilter method to apply a filter to the records in the active datasheet, form, report, or table.
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.
SetFilter (FilterName, WhereCondition, ControlName)
DoCmd.SetFilter WhereCondition:="[Product Code] Like ""NWTB*"""
Arguments
Optional arguments
The following arguments are optional
FilterName (String) - If provided, the name of a query or of a filter saved as a query. This argument or the WhereCondition argument is required.
WhereCondition (String) - If provided, a SQL WHERE clause that restricts the records in the datasheet, form, report, or table.
ControlName (String) - If provided, the name of the control that corresponds to the subform or subreport to be filtered. If empty, the current object is filtered.