Execute Query Question

Set myworkspace = DBEngine(0)
Set mydatabase = myworkspace.OpenDatabase(glocationofdb)
Set myquerydef = mydatabase.QueryDefs("qryCreateTableForCrystal")  ' Open existing QueryDef.
myquerydef.Parameters(0) = Data1.Recordset.Fields(0).Value
'the next line while it runs the Creat Table Query, it returns an error
'  3001         Invalid argument
myquerydef.Execute myquerydef

what am I doing wrong?
Who is Participating?
smeggheadConnect With a Mentor Commented:
If 'myquerydef' is of type querydef, the only parameter you can include following the execute method is 'options'

for example:
myquerydef.execute dbFAILONERROR

whereas, if you are applying the execute method to either a database or a connection (not a querydef), then the first parameter is the source (SQL string or querydef) and the second is the options...

hope this helps.
Also, I'm not sure what you're doing with workspaces. If you typed the code manually and made a few typos, I appologise for being pedantic.

You should use the syntax... (assuming you want to use the default workgroup)

set myworkspace=dbengine.workspaces(0)

dbengine is just an object, not a collection.

I know this is probably irrelevant to your question, but I just thought I'd say !!
eeevbeeeAuthor Commented:
thanks. I certainly had the wrong syntaxt. now it's working.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.