Selecting data based on multiple fields (Where And)

I have a large amount of data that I am trying to sort based on two cascading combined fields. I get a Microsoft Access can't find the field '|1' referred to in your expression error Microsoft Access can't find the field '|1' referred to in your expression and it points me to:

 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 it seems that And should work for this. What causes this error and how to resolve it?

+4
source share
1 answer
 strSQL = "Select * From [To_GE] Where [Community] = " & Chr(34) & Me.cboSubFil.Value & Chr(34) And [LCP] = "& Chr(34) & Me.cboSSubFil.Value & Chr(34)" 

May be,

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

To make reading a little easier, although I would recommend avoiding quotes or switching to single quotes in a query

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

All Articles