VBA query trouble

D

dave_b

I think I'm going blind. I have programmed SQL statements many times in the
past, and for some reason I simply cannot get anything to work right now...
I've reduced my code down to the most basic statement in order to get some
kind of error code I can comprehend. My code, at the moment, is:

docmd.runsql "Select * from MLS Sales"

Can't get much simpler than that. However, when I try to run that command
I get an error that says "A RunSQL action requires and argument consisting of
an SQL Statement."

Originally I did not use the "*" and had all my field identified. When I
did this I got the error that says "the Select statement includes a reserved
word or an argument name that is misspelled or missing or the punctuation is
incorrect."

This used to be a very simple thing to do. Can anyone give some thoughts on
this?
 
D

Dirk Goldgar

dave_b said:
I think I'm going blind. I have programmed SQL statements many times in
the
past, and for some reason I simply cannot get anything to work right
now...
I've reduced my code down to the most basic statement in order to get some
kind of error code I can comprehend. My code, at the moment, is:

docmd.runsql "Select * from MLS Sales"

Can't get much simpler than that. However, when I try to run that
command
I get an error that says "A RunSQL action requires and argument consisting
of
an SQL Statement."

Originally I did not use the "*" and had all my field identified. When I
did this I got the error that says "the Select statement includes a
reserved
word or an argument name that is misspelled or missing or the punctuation
is
incorrect."

This used to be a very simple thing to do. Can anyone give some thoughts
on
this?


You cannot "RunSQL" a SELECT query; only an action query. So this wouldn't
work even if your SQL statement were correct. As it happens, if your table
is named "MLS Sales", your SQL statement is incorrect: you need to enclose
that name in square brackets ([]):

SELECT * FROM [MLS Sales]

That correction won't make your RunSQL work, though, because it's a SELECT
query. What do you intend to do? Unfortunately, you can't open a SQL
statement as a datasheet; you would have to use a stored query for that,
and use DoCmd.OpenQuery. On the other hand, if you want to get a value from
this query and manipulate it in code, you could open a recordset on the SQL
statement.
 
M

Marshall Barton

dave_b said:
I think I'm going blind. I have programmed SQL statements many times in the
past, and for some reason I simply cannot get anything to work right now...
I've reduced my code down to the most basic statement in order to get some
kind of error code I can comprehend. My code, at the moment, is:

docmd.runsql "Select * from MLS Sales"

Can't get much simpler than that. However, when I try to run that command
I get an error that says "A RunSQL action requires and argument consisting of
an SQL Statement."

Originally I did not use the "*" and had all my field identified. When I
did this I got the error that says "the Select statement includes a reserved
word or an argument name that is misspelled or missing or the punctuation is
incorrect."

This used to be a very simple thing to do.

That's not supposed to work, RunSQL inly operates on action
type queries (Insert Into, Update, Delete, etc), not Select
queries. You never said what you are trying to accomplish
so I can't guess what you should be using.
 

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 -- VBA 3
SQL Query in VBA 9
SQL - VBA once again 10
Using Date fields in SQL 2
SQL statement doesn't work in VBA. 2
Stop Query 4
Open select query in vba code 4
Running a SELECT statement 2

Top