Thursday, November 26, 2020

Filter property

Applies to

Form Object

Report Object

You can use the Filter property to specify a subset of records to be displayed when a filter is applied to a form, reportquery, or table. Read/write String.

expression.Filter

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

Remarks

If you want to specify a server filter within a Microsoft Access project (.adp) for data located on a server, use the ServerFilter property.

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

Me.Filter = "CountryRegion = 'USA'"
Me.FilterOn = True

You can set this property by using a table's or form's property sheet, a macro, or VBA code.

You can also set this property in Form view, Report view, Datasheet view, or Layout view, by clicking Filter or Selection under Sort & Filter on the Data tab and clicking one of the commands on the submenu.

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

You can use the Filter 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.

When a new object is created, it inherits the RecordSource , Filter, OrderBy , and OrderByOn properties of the table or query it was created from.

To apply a saved filter to a form, query, or table, you can click Toggle Filter under Sort & Filter on the Data tab, or use a macro or VBA code to set the FilterOn property to True. For reports, you can apply a filter by setting the FilterOn property to Yes in the report's property sheet.

The Toggle Filter button indicates the state of the Filter and FilterOn properties. The button remains disabled until there is a filter to apply. If an existing filter is currently applied, the Toggle 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.

You can remove a filter by clicking the pressed-in Toggle Filter button, right-clicking the filtered field and clicking Clear filter from..., or using VBA code to set the FilterOn property to False.

No comments:

Post a Comment