0

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

1
  • What is the value of Lping when running RunSQL() ? Commented Jul 23, 2015 at 0:35

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.