ApplyFilter Method

Microsoft Access Visual Basic

action in Visual Basic.

expression.ApplyFilter(FilterName, WhereCondition)

expression    Required. An expression that returns one of the objects in the Applies To list.

FilterName   Optional Variant. A string expression that's the valid name of a filter or query in the current database. When using this method to apply a server filter, the FilterName argument must be blank.

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

Remarks

For more information on how the action and its arguments work, see the action topic.

The filter and WHERE condition you apply become the setting of the form's Filter property or report's ServerFilter property.

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.

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'"