ServerFilter Property

ServerFilter Property

See Also                  Applies To

You can use the ServerFilter property to specify a subset of records to be displayed when a server filter is applied to a form or report within a Microsoft Access project (.adp) or a data access page in a Microsoft Access project (.adp) or database (.mdb).

Setting

The ServerFilter property is a string expression consisting of a WHERE clause without the WHERE keyword. For example, the following Visual Basic code defines and applies a filter to show only customers from the USA:

Me.ServerFilter = "Country = 'USA'"
Me.ServerFilterByForm = True

The easiest way to set this property is by using a form or report's property sheet. You can also set this property on a form or report by using Visual Basic.

To set the ServerFilter property, you must first either:

Note   Setting the ServerFilter property has no effect on the ADO Filter property.

Remarks

You can use the ServerFilter property to save a filter 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 aren't automatically applied.

To apply a saved filter to a form, you can click Apply Server Filter on the toolbar, click Apply Filter/Sort on the Records menu, or use a macro or Visual Basic to set the ServerFilterByForm property to True (–1).

The Apply Server Filter button indicates the state of the ServerFilter and ServerFilterByForm properties. The button remains disabled until there is a filter to apply. If an existing filter is currently applied, the Apply Server Filter button appears pressed in.

To apply a filter automatically when a form is opened, specify in the OnOpen event property setting of the form either a macro that uses the ApplyFilter action or an event procedure that uses the ApplyFilter method of the DoCmd object. In either case, the form opens in the Server Filter By Form window.

You can only remove a server filter by using Visual Basic to set the ServerFilterByForm property to False (0) or clear all filter criteria in the Server Filter By Form window and then click Apply Server Filter.

When the ServerFilter property is set in form Design view, Microsoft Access does not attempt to validate the SQL expression. If the SQL expression is invalid, an error occurs when the filter is applied.

Notes