G
Guest
Hello,
I get the subject error message when I run an ADO query from MS Access.
The query works ok if I don't include the WHERE statement. If I run the
query from Access query editor, it works ok.
SELECT * FROM tblNames WHERE tblNames.Name"Brown, John";
this is my code... appreciate any help given.
regards,
bobm
Sub test()
strName = "Brown, John"
strPath = "C:\mydatabase.mdb"
Set cn1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset
'strSQL = "SELECT * FROM tblNames;"
strSQL = "SELECT * " & _
"FROM tblNames " & _
"WHERE tblNames.Name" & """" & strName & """" & ";"
Debug.Print strSQL
cn1.Open "Driver={Microsoft Access Driver (*.mdb)}; Dbq=" & strPath &
";Pwd=leave;"
rs1.Open strSQL, cn1, adOpenKeyset, adLockPessimistic, adCmdText
Do Until rs1.EOF
Debug.Print rs1.Fields("Name")
rs1.MoveNext
Loop
rs1.Close
cn1.Close
Set cn1 = Nothing
Set rrs1 = Nothing
End Sub
I get the subject error message when I run an ADO query from MS Access.
The query works ok if I don't include the WHERE statement. If I run the
query from Access query editor, it works ok.
SELECT * FROM tblNames WHERE tblNames.Name"Brown, John";
this is my code... appreciate any help given.
regards,
bobm
Sub test()
strName = "Brown, John"
strPath = "C:\mydatabase.mdb"
Set cn1 = New ADODB.Connection
Set rs1 = New ADODB.Recordset
'strSQL = "SELECT * FROM tblNames;"
strSQL = "SELECT * " & _
"FROM tblNames " & _
"WHERE tblNames.Name" & """" & strName & """" & ";"
Debug.Print strSQL
cn1.Open "Driver={Microsoft Access Driver (*.mdb)}; Dbq=" & strPath &
";Pwd=leave;"
rs1.Open strSQL, cn1, adOpenKeyset, adLockPessimistic, adCmdText
Do Until rs1.EOF
Debug.Print rs1.Fields("Name")
rs1.MoveNext
Loop
rs1.Close
cn1.Close
Set cn1 = Nothing
Set rrs1 = Nothing
End Sub