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
 
Top