DoCmd.RunSQL

  • Thread starter Thread starter Vsn
  • Start date Start date
V

Vsn

Hello all,

Can someone explane why I can not execute the following code, I get an error
message 2342.

DoCmd.RunSQL ("SELECT * FROM MSysObjects WHERE (((MSysObjects.Type)=6))")

Thx alot.

Ludovic
 
RunSQL only works with Action queries (that is, SELECT ... INTO, INSERT
INTO, UPDATE or DELETE queries)

You need to open a recordset and work with the recordset, or else save the
SQL as a query, and run the query to open the standard grid that's returned
by a query.
 
RunSQL method is used only for action query SQL statements. For a select
query, there is no corresponding method in the DoCmd object library (you can
use the OpenQuery method to open a stored query, but you cannot use it to
run your own SQL statement)

What are you wanting to do when you run this query from code?
 
Guys,

Sorry have been away for a bit.

Well the idea was that I would just open a query from code without having a
regular query stored. Thus not creating loads of queries in the list.

Thx,
Ludovic
 
You cannot "create" a query in code only and then view the dataset just as
if you'd opened it from the Database window ... you can do that only for
saved queries. And typically, one would use a form or report to view the
results of such a query. You can open a form or report and set its
RecordSource to be an SQL statement (query) that is not saved as a query --
so perhaps that will be a better way for you to go?
 
Back
Top