running query

A

azhu.uwaterloo

Hello,
I was trying to create a chunk of code like follows:

Dim qry As DAO.QueryDef 'the actual query to be generated
Dim qryName As String 'the name given to the query


sql = "SELECT * INTO AppendAllFields FROM [some table];"
Set qry = db.CreateQueryDef(qryName, sql)
DoCmd.OpenQuery (qryName)
where qryname is alr. defined.

When I wronf it, it kept giving me the error on the DoCmd line saying
that runtime error 3001, invalid argument....

Anyone could help?

Thanks!
 
J

John W. Vinson

Hello,
I was trying to create a chunk of code like follows:

Dim qry As DAO.QueryDef 'the actual query to be generated
Dim qryName As String 'the name given to the query


sql = "SELECT * INTO AppendAllFields FROM [some table];"
Set qry = db.CreateQueryDef(qryName, sql)
DoCmd.OpenQuery (qryName)
where qryname is alr. defined.

When I wronf it, it kept giving me the error on the DoCmd line saying
that runtime error 3001, invalid argument....

I'd suggest not using OpenQuery. Use the querydef's Execute operator instead:

Set qry = db.CreateQuerydef("", sql) ' create an unnamed query definition
qry.Execute dbFailOnError

If you do want to save the query for later use, you can indeed use qryName -
but you do need to provide some name in that string variable.

John W. Vinson [MVP]
 

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