Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open query from another database

Status
Not open for further replies.

Duke12

Programmer
Feb 5, 2002
1
AT
Hi! I'm a newbie to this subject and need help. I have 2 databases: let's say 1 and 2. In db 2 i put a query. Now i want to start db 2 from db1 and want to execute the query using vba-code. I only managed to have access to tables but not to queries yet. Please help (maybe with an example).
THX
 
I do not know exactly how you managed to open the second database from the first one, but I assume you declared a new Database object and then set its value to the second database.

If that was how you got in (let's say that the second database is called DB2), all you need to do is to execute:

DB2.Application.DoCmd.OpenQuery "name of query"

Hope it helps.
 
Duke12,

See if the following works,

Dim db1 As Database, db2 As Database
Dim rst1 As Recordset, rst2 As Recordset

Set db1 = OpenDatabase("C:\Temp\A.mdb")
Set db2 = OpenDatabase("C:\Temp\B.mdb")

Set rst1 = db1.OpenRecordset("qry1")
Set rst2 = db1.OpenRecordset("qry2")
.
.
.
rst1.Close
rst2.Close
db1.Close
db2.Close
[COLOR=/b]
HTH,
GGleason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top