OpenRecordset results in "syntax error (missing operator)" messag

G

Guest

I have two OpenRecordsets that work fine separately. When I try to AND them
together I get the following message: "... syntax error (missing operator)
in query expression ...". The two OpenRecordsets are below, followed by the
flawed OpenRecordset with the And:

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
[Manager #]=" & [Manager], dbOpenDynaset) ' works fine

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where [Agent
Name]= '" & AgtName & "'", dbOpenDynaset) ' works fine

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
([Manager #]= & [Manager] and [Agent Name]= '" & AgtName & "'",
dbOpenDynaset) ' results in syntax error
 
S

SusanV

Try using this syntax:
Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
([Manager #]= & [Manager] AND WHERE [Agent Name]= '" & AgtName & "'",
dbOpenDynaset)
 
F

fredg

I have two OpenRecordsets that work fine separately. When I try to AND them
together I get the following message: "... syntax error (missing operator)
in query expression ...". The two OpenRecordsets are below, followed by the
flawed OpenRecordset with the And:

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
[Manager #]=" & [Manager], dbOpenDynaset) ' works fine

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where [Agent
Name]= '" & AgtName & "'", dbOpenDynaset) ' works fine

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
([Manager #]= & [Manager] and [Agent Name]= '" & AgtName & "'",
dbOpenDynaset) ' results in syntax error

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
([Manager #]= " & [Manager] & " and [Agent Name]= '" & AgtName & "'",
dbOpenDynaset)
 
J

John Spencer (MVP)

IS it me? I see an extra ( in the SQL statement between "WHERE " and "[Manager
#]". At least I don't see the balancing ")"
I have two OpenRecordsets that work fine separately. When I try to AND them
together I get the following message: "... syntax error (missing operator)
in query expression ...". The two OpenRecordsets are below, followed by the
flawed OpenRecordset with the And:

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
[Manager #]=" & [Manager], dbOpenDynaset) ' works fine

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where [Agent
Name]= '" & AgtName & "'", dbOpenDynaset) ' works fine

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
([Manager #]= & [Manager] and [Agent Name]= '" & AgtName & "'",
dbOpenDynaset) ' results in syntax error

Set rs = CurrentDb.OpenRecordset("Select * From [AgentDataBase] Where
([Manager #]= " & [Manager] & " and [Agent Name]= '" & AgtName & "'",
dbOpenDynaset)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top