RunSQL Vs Execute ?

M

mscertified

What is the difference between (and is either preferred):

Docmd.RunSQL "SQL statement"

and

CurrentProject.Connection.Execute "SQL statement"
 
J

John W. Vinson

What is the difference between (and is either preferred):

Docmd.RunSQL "SQL statement"

and

CurrentProject.Connection.Execute "SQL statement"

One big difference is that the former does not let you trap errors, and the
latter does.
 
D

Dale Fye

It's been so long since I've used RunSQL.

Doesn't it require SetWarning Off/On to prevent warnings as well?

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
J

John W. Vinson

It's been so long since I've used RunSQL.

Doesn't it require SetWarning Off/On to prevent warnings as well?

Yep - that's another of its disadvantages vis a vis the Execute method.
 
M

mscertified

And the .execute method allows you to get the 'records affected' count back -
which is sometimes very useful.
 
M

Marshall Barton

mscertified said:
What is the difference between (and is either preferred):

Docmd.RunSQL "SQL statement"

and

CurrentProject.Connection.Execute "SQL statement"


IMO, the only dubious advantage of RunSQL is that Access
runs it. This means that the SQL can reference form
controls.

OTOH, it only takes a few of lines of code to deal with
parameters for use with Execute.
 
Top