DoCmd.RunSQL not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
DoCmd.RunSQL is used to run action queries, not select queries.

Use DoCmd.OpenQuey instead for your query.
 
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 ....
 
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.
 
Back
Top