CurrentDb.Execute leads to Run-time error '3061'

MartinRi

New member
Local time
Yesterday, 17:46
Joined
Jul 28, 2015
Messages
3
Hi all,

I use Access 2007.

This code leads to "Run-time error '3061'. Too few parameters. Expected 1."

Code:
 Sub calc_t1_Click()
 
  CurrentDb.Execute "INSERT INTO t1 (c1,c2) SELECT c1, c2 FROM v_t2;"
  
 End Sub
I can execute the same statement in a new query and everything works! But it does not work in VBA.

Maybe it is important to know that the view v_t2 is very complex.

Any ideas?

Thank you,
Martin
 
Hi,

That problem gave me a bad headache for the last two days and the solution came to me just by sharing it with you ;)

Workaround:
I saved the Statement in a query, which is now called "ins_t2".
My VBA Code is as follows:

DoCmd.OpenQuery "ins_t2"

As simple as that- it works.

I am just still wondering why I cannot execute the complete Statement within VBA...

I do not know how to flag this thread as solved. Hope it doesn't matter :confused:

Bye,
Martin
 
Expression service - interpreting Access-bits and references to controls - is not available in .Execute, so it falls over on not knowing what has been said.

Queries with parametres are best dealt with using the QueryDef object. You'd have found it by googling for your runtime error. Most errors have been seen and dealt with. (Yes, this is a hint to use Google).
 

Users who are viewing this thread

Back
Top Bottom