Microsoft Access VBA Programming for the Absolute Beginner

Applies a filter to a table, form, or report.

Syntax

DoCmd.ApplyFilter [FilterName][, WhereCondition]

with the following parameters:

FilterName

The name of a filter saved as a query, or of a query to which a filter condition is to be attached.

WhereCondition

The WHERE clause of a SQL statement (the filter).

Example

Private Sub cmdFilter_Click() Dim strState As String, strFilter As String strState = InputBox("Enter state whose customers will be shown:") ' If null string, clear filter If strState = "" Then DoCmd.ShowAllRecords Else strFilter = "txtState = '" & strState & "'" DoCmd.ApplyFilter , strFilter End If Debug.Print Me.Filter End Sub

Comments

Категории