ApplyFilter


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

  • Calling the ApplyFilter method is equivalent to setting the Filter property of a form.

  • The WhereCondition clause does not actually include the SQL WHERE keyword, as the example shows.

  • To clear a filter, you can either assign a null string to a form’s Filter property or call DoCmd.ShowAllRecords.

  • Either the FilterName or the WhereCondition argument should be supplied. If both are supplied, WhereCondition is used.




Access VBA Programming
Microsoft Access VBA Programming for the Absolute Beginner
ISBN: 1598633937
EAN: 2147483647
Year: 2006
Pages: 214
Authors: Michael Vine

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net