Table of contents

使用条件表达式中的多个字段Use Multiple Fields in Criteria Expressions

office 365 dev account|上次更新日期: 2017/9/25
1 参与者

您可以在_criteria_参数中指定多个字段。You can specify multiple fields in a criteria argument.

在_criteria_参数中指定多个字段,您必须确保正确连接多个字符串表达式以形成一个有效 SQL WHERE 子句。SQL WHERE 子句中使用多个字段,字段可能加入用三个关键词之一: ANDOR,或。表达式必须对包含这些关键字之一的字符串。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.

例如,假设您要将雇员窗体显示由两组条件限制的记录的筛选器属性设置。下面的示例筛选窗体以便显示只有那些雇员的职务是"销售代表"和雇佣的自 1993 年 1 月 1 日以来:For example, suppose that you want to set the Filter 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:

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

Criteria_参数的计算结果为下面的字符串:The _criteria argument evaluates to the following string:

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

若要解决_criteria_参数中表达式的错误,最好将表达式拆分为较小的组件,并在立即窗口中逐个测试。当所有的组件都工作正常时,将它们放到一起直到整个表达式能够正常工作。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.

© 2018 Microsoft