VBA DoCmd.RunSQL

K

Karen Boyer

The following statement produces an error that DoCmd.RunSQL requires an
argument that is an SQL statement:

DoCmd.RunSQL "SELECT * & _
"FROM _SCHOOLS"

_SCHOOL is the name of my Access table.

Why is this not a valid SQL statement?

Thank you for your advice.


Sincerely,

Karen Boyer
Xetex Business Systems
610-898-1551
1-800-356-2772
Ext 12
 
T

Tom Lake

Karen Boyer said:
The following statement produces an error that DoCmd.RunSQL requires an
argument that is an SQL statement:

DoCmd.RunSQL "SELECT * & _
"FROM _SCHOOLS"

_SCHOOL is the name of my Access table.

Why is this not a valid SQL statement?

Thank you for your advice.

Is the name _SCHOOL or is it _SCHOOLS? You have it both ways.
In either case you need an action statement (INSERT INTO, DELETE,
SELECT...INTO, UPDATE, CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX,
or DROP INDEX) rather than just a SELECT and you also need a semi-colon at
the end of the SQL statement.

Tom Lake
 
F

fredg

The following statement produces an error that DoCmd.RunSQL requires an
argument that is an SQL statement:

DoCmd.RunSQL "SELECT * & _
"FROM _SCHOOLS"

_SCHOOL is the name of my Access table.

Why is this not a valid SQL statement?

Thank you for your advice.

Sincerely,

Karen Boyer
Xetex Business Systems
610-898-1551
1-800-356-2772
Ext 12

You can only run an Action query (Update, Append, Delete, etc.) using
RunSQL, not a Select Query.

Read VBA help on the RunSQL method.

Note If "_School" is the name of the table, you using
"From _Schools" in the SQL.
_School is not the same as _Schools.
 

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

SQL Error 2
VBA -- SQL 9
DoCmd.RunSQL not working 4
SQL -- VBA 3
VBA query trouble 4
SQL statement doesn't work in VBA. 4
DoCmd.RunSQL error Help 5
Problem with DoCMD.RUNSQL Select statement 7

Top