ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using excel to access MS Access saved query (https://www.excelbanter.com/excel-programming/409574-using-excel-access-ms-access-saved-query.html)

matelot

Using excel to access MS Access saved query
 
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

roger

Using excel to access MS Access saved query
 
"matelot" wrote in message
...
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")

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?



--
roger




All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com