ApplyFilter Method

Applies To

DoCmd object.

Description

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.

Syntax

DoCmd.ApplyFilter [filtername][, wherecondition]

The ApplyFilter method has the following arguments.

Argument

Description

filtername

A string expression that's the valid name of a query in the current database.

wherecondition

A string expression that's a valid SQL WHERE clause without the word WHERE.


Remarks

You must include at least one of the two ApplyFilter method arguments. If you enter a value for both arguments, the wherecondition argument 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 argument's comma.

See Also

ApplyFilter action, Filter property, FilterOn property, OpenForm method, OpenQuery method, OpenReport method, ShowAllRecords method.

Example

The following example uses the ApplyFilter method to display only records that contain the name King in the LastName field:

DoCmd.ApplyFilter , "LastName = 'King'"