Using excel to access MS Access saved query

M

matelot

I use the following code to open Access db and run a sql.
set dbs=opendatabase(dbname)
set qry= dbs.createquerydef("queryname")
qry.sql="select name from customers"
set rst = qry.openrecordset()
Activesheet.range("A1").copyfromrecordset rst

It's working fine. However, I have multiple saved queries in MS Access that
I would like to access from Excel VBA. I tried replacing "queryname" to the
saved query name and it's not working. Am I missing something?

Thanks
 
R

roger

matelot said:
I use the following code to open Access db and run a sql.
set dbs=opendatabase(dbname)

You don't need the next two lines, which are for creating a new query
set qry= dbs.createquerydef("queryname")
qry.sql="select name from customers"

use this instead -

set qry= dbs.querydefs("queryname")
 

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