使用多个组合框过滤数据

时间:2018-07-31 18:16:52

标签: ms-access

我遵循了youtube教程,但是在查询表达式'[YPName] ='CliveAND [ContactType] ='Social Worker'中出现以下运行时错误-3075-语法错误(缺少运算符)。

Clive是“ YP名称”,而Social Worker是“ ContactType”

这是新手,而且很挣扎。有什么想法使我的代码出错吗?

YPName和ContactType是我要过滤的数据库中的两个字段。 我的组合框以字母“ cbo”开头

Function SearchCriteria()
Dim YPName, strContactType As String
Dim task, strCriteria As String

If IsNull(Me.cboNameOfYP) Then
    YPName = "[YPName] like '*'"
Else
    YPName = "[YPName] = '" & Me.cboNameOfYP
End If

If IsNull(Me.cboContactType) Then
    strContactType = "[ContactType] like '*'"
Else
    strContactType = "[ContactType] = '" & Me.cboContactType & "'"
End If
strCriteria = YPName & "And" & strContactType
    task = "Select * from tblContactList where " & strCriteria
    Me.tblContactList_subform.Form.RecordSource = task
    Me.tblContactList_subform.Form.Requery


End Function

0 个答案:

没有答案