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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a query in another database 1

Status
Not open for further replies.

merlynsdad

Programmer
Nov 18, 2010
175
US
I do way more VBA in Excel than Access, but this time I need to open a query in another db from my db. I'm basically using the same code to run the other db that the other db uses, with a modified Set db=OpenDatabase("path"). However, I'm having trouble with the password on the other db. The code in the other db to run the password is

DoCmd.OpenQuery "Logon_q"
DoCmd.Close acQuery, "Logon_q"

This gives a "can't find the object 'Login_q' error in my db. How do I open and close this query from my db?

If the square peg won't fit in the round hole, sand off the corners.
 
Put a public procedure in you external database

public sub openLogonq()
docmd.openquery "Logon_q"
end sub

public sub closeLogonq()
docmd.close acquery, "Logon_q"
end sub

Go to references in the database window and add the external database as a reference

from the maindatabase you can now call these procedures and open forms, queries, etc, in the external database as if they are in your database.

when calling from the main database you may have to use the project name of the external database.

theprojectname.openLogonq
 
Thanks, dhookom. Since I can't modify the external db, your one liner works perfectly.

If the square peg won't fit in the round hole, sand off the corners.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top