Reputation: 615
Using the following code that generates
Error:(2342) A Run SQL action requires an action consisting of an SQL statement
Here is the code:
Dim Lping As Variant
Lping = "SELECT dbo_Log_Table.LogID"
Lping = Lping + " FROM dbo_Log_Table"
Lping = Lping + " WHERE (((dbo_Log_Table.LogID)=1))"
DoCmd.SetWarnings False
DoCmd.RunSQL Lping
DoCmd.SetWarnings True
The SQL is copied from the QBE grid and executes from there. I have other such code, but can't see the problem with this.
Thanks in advance
JPL
Upvotes: 0
Views: 55
Reputation: 12245
The problem is that DoCmd.RunSQL
runs action statements: Insert
, Update
, Delete
. A select statement doesn't do anything. You have no way of obtaining the results of this query and using them and thus RunSQL
doesn't even let you waste your time doing it.
If you want to use the results of this query you'll need to create a QueryDef
, a query object and use that, or explicitly generate a recordset. Either way the Query needs to get into a recordset to be used.
Upvotes: 2