Access Reference

Multiple fields in criteria expressions

Direct Answer

Multiple fields in criteria expressions
is part of the Access VBA object model. This reference page documents its syntax, parameters, and typical usage.

Reference

You can specify multiple fields in a _criteria_ argument.

To specify multiple fields in the _criteria_ argument, you must ensure that multiple string expressions are concatenated correctly to form a valid SQL WHERE clause. In an SQL WHERE clause with multiple fields, fields may be joined with one of three keywords: AND, OR, or NOT. Your expression must evaluate to a string that includes one of these keywords.

For example, suppose that you want to set the Filter.md) property of an Employees form to display records restricted by two sets of criteria. The following example filters the form so that it displays only those employees whose title is “Sales Representative” and who were hired since January 1, 1993:

“`vb
Dim datHireDate As Date
Dim strTitle As String

datHireDate = #1/1/93#
strTitle = “Sales Representative”

Forms!Employees.Filter = “[HireDate] >= #” & _
datHireDate & “# AND [Title] = ‘” & strTitle & “‘”
Forms!Employees.FilterOn = True
“`

The _criteria_ argument evaluates to the following string:

"[HireDate] >= #1-1-93# AND [Title] = 'Sales Representative'"

> TIP:
> To troubleshoot an expression in the _criteria_ argument, break the expression into smaller components and test each individually in the Immediate window. When all of the components are working correctly, put them back together one at a time until the complete expression works correctly.

!include[Support and feedback]

Reference: Access object-model documentation • updated 09/21/2018
. Rebuilt for readability; see the original for complete parameter matrices.