基于多个字段选择数据(Where And)

时间:2012-11-30 18:22:24

标签: sql forms vba select

我有大量的数据,我试图根据两个级联组合框进行整理。我收到错误Microsoft Access can't find the field '|1' referred to in your expression并指出:

ElseIf [Forms]![Send To GE]![cboFil] = "LCP" Then
strSQL = "Select * From [To_GE] Where [Community] = " & Chr(34) & Me.cboSubFil.Value & Chr(34) And [LCP] = "& Chr(34) & Me.cboSSubFil.Value & Chr(34)"
Set rst = db.OpenRecordset(strSQL)    

似乎And应该适用于此。是什么导致了这个错误,我该如何解决?

1 个答案:

答案 0 :(得分:3)

strSQL = "Select * From [To_GE] Where [Community] = " & Chr(34) & Me.cboSubFil.Value &     Chr(34) And [LCP] = "& Chr(34) & Me.cboSSubFil.Value & Chr(34)"

应该是

strSQL = "Select * From [To_GE] Where [Community] = " & Chr(34) & Me.cboSubFil.Value & Chr(34) & " And [LCP] = " & Chr(34) & Me.cboSSubFil.Value & Chr(34)

为了让阅读更容易,我会建议在查询中转义引号或切换到单引号

strSQL = "Select * From [To_GE] Where [Community] = '" & Me.cboSubFil.Value & "' And [LCP] = '" & Me.cboSSubFil.Value & "'"