Use query from another database

M

m.fisher

Hi

In the code below is there a way that qryOrderHistory could be in a
separate database. If so how would i refer to it in the code.

Thanks


Dim db As DAO.Database
Dim qd As DAO.Querydef
Dim rs As DAO.Recordset

Set db = CurrentDb
Set qd = db.QueryDefs("qryOrderHistory")
qd.Parameters("prmCustNo") = lngCustNo

Set rs = qd.OpenRecordset()

If Not rs.Eof Then

.... code to populate an excel spreadsheet
 
B

Brendan Reynolds

Change your 'Set db = CurrentDb' line to something like the following ..

Set db = DbEngine.OpenDatabase("full path and name of target MDB here")
 
I

i_takeuti

Hi

In the code below is there a way that qryOrderHistory could be in a
separate database. If so how would i refer to it in the code.

Thanks


Dim db As DAO.Database
Dim qd As DAO.Querydef
Dim rs As DAO.Recordset

Set db = CurrentDb
Set qd = db.QueryDefs("qryOrderHistory")
qd.Parameters("prmCustNo") = lngCustNo

Set rs = qd.OpenRecordset()

If Not rs.Eof Then

... code to populate an excel spreadsheet
 

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