DoCmd Object.
The ApplyFilter method carries out the ApplyFilter action in Visual Basic. For more information on how the action and its arguments work, see the action topic.
DoCmd.ApplyFilter [filtername] [, wherecondition]
The ApplyFilter method uses the following arguments.
Argument | Description |
filtername | A string expression that is the valid name of a query in the current database. |
wherecondition | A string expression that is a valid SQL WHERE clause without the word WHERE. |
You must include at least one of the two ApplyFilter arguments. If you enter a value for both arguments, wherecondition is applied to the filter.
The maximum length of the wherecondition argument is 32,768 characters (unlike the Where Condition action argument in the Macro window, whose maximum length is 256 characters).
If you specify the wherecondition argument and leave the filtername argument blank, you must include the filtername arguments comma.
ApplyFilter Action, DoCmd Object, Filter Property, FilterOn Property, OpenForm Method, OpenQuery Method, OpenReport Method, ShowAllRecords Method.
This example uses the ApplyFilter method to display only records that contain the name King in the LastName field.
DoCmd.ApplyFilter , "[LastName] = 'King'"