DoCmd.OpenQuery vs CurrentDb.Execute

A

Andreas

From my form:
DoCmd.OpenQuery "Quotation-to-Invoice Query", , acAdd

Works fine but I cannot get error code.

CurrentDb.Execute "Quotation-to-Invoice Query", dbFailOnError

Doesn't work. Returns error 3061 - too few parameters. Expected 1.
 
S

Smartin

Andreas said:
From my form:
DoCmd.OpenQuery "Quotation-to-Invoice Query", , acAdd

Works fine but I cannot get error code.

CurrentDb.Execute "Quotation-to-Invoice Query", dbFailOnError

Doesn't work. Returns error 3061 - too few parameters. Expected 1.

The Execute method is only valid for action queries. I'm guessing you
have a SELECT (but not SELECT INTO) query.
 
A

Andreas

I have INSERT INTO which later uses SELECT in order to filter what to append
into a specific field.
 
M

Marshall Barton

Andreas said:
From my form:
DoCmd.OpenQuery "Quotation-to-Invoice Query", , acAdd

Works fine but I cannot get error code.

CurrentDb.Execute "Quotation-to-Invoice Query", dbFailOnError

Doesn't work. Returns error 3061 - too few parameters. Expected 1.


OpenQuery opens a Select query in datasheet view. Execute
(and RunSQL) run action queries without displaying anything
on the screen. I don't see where you have a choice between
them. I also don't see where an error can come up for a
Select query unless you have ill formed parameters, in which
case Execute probably will generate the usual trappable
errors whether you use dbFailOnError or not.

OpenQuery and RunSQL are Access methods that include query
parameter resolution. Since Execute goes directly to the
data provide library, you have to resolve the query
parameters in your code.
 

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

Top