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.
 

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

Similar Threads

DoCmd.RunSQL HELP!!! I will not work! 1
SQL Error 2
VBA -- SQL 9
VBA DoCmd.RunSQL 2
SQL -- VBA 3
SQL statement doesn't work in VBA. 4
Using Date fields in SQL 2
MultiSelect Listbox 5

Top