CurrentDb.Execute

  • Thread starter Thread starter Ed Carron
  • Start date Start date
E

Ed Carron

When I run a CurrentDb.Execute statement with a stored Access Insert Query
as the first argument, and dbFailOnError as the second argument, I get an
error message "Too few parameters. Expected 3."

When I rewrite the statement to have a hard-coded insert statement as the
first argument, and dbFailOnError as the second argument, the code works
fine.

Problem is I need to run the execute with the stored Access Insert Query
that gets its insert values from controls on the active form.

Is there a way that I can do that?

Thanks,

Ed
 
Hi Ed

It means that your query is referring to three "parameters" that Jet SQL
cannot resolve. It may not look like a parameter query, but if it refers,
for example, to controls on an open form, then these are in fact parameters.
Access can resolve them if you open the query or a form/report based on the
query, but Jet SQL cannot.

Fortunately, you can help Jet out by evaluating all the parameters before
the query is executed:

Dim q As DAO.QueryDef, p As DAO.Parameter
Set q = DBEngine(0)(0).QueryDefs("YourQuery")
For Each p In q.Parameters
p.Value = Eval(p.Name)
Next
q.Execute dbFailOnError
 
Back
Top