Error on DoCmd.RunSQL

D

daved

I have the code:

Private Sub txtEmpNo_AfterUpdate()

Dim strSQL As String
Dim EmpNo As String

strSQL = "SELECT EmpNo FROM tblEmployees;"
==> DoCmd.RunSQL strSQL

If Forms!frmTimeClock!txtEmpNo = EmpNo Then
MsgBox "OK"
Else
MsgBox "Not OK!"
End If

End Sub

I'm getting error message #2342
"A RunSQL action requires an argument consisting of an SQL statemnent."

I don't know how to fix this.. I have used the technique before and have
never gotten this error. This is however on an upgrade from Access 2002 to
Access 2003.

Dave D.
 
K

Klatuu

The RunSQL method is only for action queries. Your SQL is a select query.
You could not have used this technique before, it has never worked.

Perhaps what you are trying to do is

Dim rst As Recordset

strSQL = "SELECT EmpNo FROM tblEmployees;"
Set rst = Currentdb.OpenRecordset(strSQL)
If Forms!frmTimeClock!txtEmpNo = rst!EmpNo Then
MsgBox "OK"
Else
MsgBox "Not OK!"
End If

Even then, there is nothing in your code that explains how you expect to
match up the employee number on the form with that in the recordset.
 
F

fredg

I have the code:

Private Sub txtEmpNo_AfterUpdate()

Dim strSQL As String
Dim EmpNo As String

strSQL = "SELECT EmpNo FROM tblEmployees;"
==> DoCmd.RunSQL strSQL

If Forms!frmTimeClock!txtEmpNo = EmpNo Then
MsgBox "OK"
Else
MsgBox "Not OK!"
End If

End Sub

I'm getting error message #2342
"A RunSQL action requires an argument consisting of an SQL statemnent."

I don't know how to fix this.. I have used the technique before and have
never gotten this error. This is however on an upgrade from Access 2002 to
Access 2003.

Dave D.

Read VBA help on the RunSQL method.
You cannot run a Select query using RunSQL, only action queries, i.e.
Delete, Update, etc.
 

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