DoCmd.RunSQL not working

B

BillS

I am having trouble using the RunSQL command. I am receiving, " A RunSQL
action requires an argument consisting of an SQL statement". The statement is
very simple and works in the query builder but not in code.

DoCmd.RunSQL "SELECT tblChecks.strCkNum, tblChecks.strPayee FROM tblChecks"

I have also tried:

Dim sql As String
sql = "SELECT tblChecks.strCkNum, tblChecks.strPayee FROM tblChecks"

DoCmd.RundSQL sql

What am I doing wrong?
 
K

Ken Snell [MVP]

DoCmd.RunSQL is used to run action queries, not select queries.

Use DoCmd.OpenQuey instead for your query.
 
D

Dennis

The RunSQL statement is for appending to a table, updating a table, deleting
from a table or make table. Your statement does non of these.
the syntax is
DoCmd.RunSQL "INSERT INTO ....
DoCmd.RunSQL "UPDATE .....
DoCmd.RunSQL "DELETE ....
DoCmd.RunSQL "SELECT .... INTO ....
 
C

Chaim

Bill,

According to the Microsoft Visual Basic Help for the RunSQL method, the SQL
has to be an 'action query' or a 'data definition query'. SELECT is not an
action query. SELECT ... INTO (to create a table from another data source) is.

See the help page.
 
Top