Share via

Run query in another database

Anonymous
2010-11-08T17:08:31+00:00

Hi

Is it possible to run Query_A in Database_A from Database_B?

Thanks

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-11-08T17:17:55+00:00

You could use straight forward vba database automation or I also came across another example where you can add the other db as a reference within your 2nd db and call the query, see:http://www.access-programmers.co.uk/forums/showthread.php?t=156716.  It depends a little on what exactly you are trying to do.


Daniel Pineault, 2010-2011 Microsoft MVP

http://www.cardaconsultants.com

MS Access Tips and Code Samples: http://www.devhut.net

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-11-09T12:22:27+00:00

    Thanks Daniel

    I took the easy route and just linked the relevant tables. Then ran the query in Database_B

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-11-09T12:20:00+00:00

    David-W-Fenton wrote:

    Karl Donaubauer wrote

    Set db =

    DBEngine.Workspaces(0).OpenDatabase("c:\path\Another.mdb")

    Just curious, but is there a difference between that and

    DBEngine.OpenDatabase()? I would assume the shorter version is going

    to use the default workspace, and have never used anything else.

    Yes, you're right.

    I have used all 3 ways (also simply OpenDatabase()) depending on

    the mood or where I copied the line from ;-) (this time from my website).

    A short test proves that even setting the db immediately

    after appending a new workspace:

    ...

    Set wrkJet = CreateWorkspace("mySpace", "admin", "")

    DBEngine.Workspaces.Append wrkJet

    Set db = DBEngine.OpenDatabase("Some.mdb")

    or

    Set db = OpenDatabase("Some.mdb")

    a loop through the databases collections shows that

    the default workspace is used.

    A different workspace is only used when stated explicitely:

    Set db = DBEngine.Workspaces(1).OpenDatabase("Some.mdb")

    or

    Set db = Workspaces("mySpace").OpenDatabase("Some.mdb")

    etc.

    So there's no need to do more than

    Set db = OpenDatabase()


    cu

    Karl

    *******

    Access-FAQ (German/Italian): http://www.donkarl.com

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-11-08T21:20:00+00:00

    Karl Donaubauer [MVP] wrote in

    news:*** Email address is removed for privacy ***

    m:

    Set db =

    DBEngine.Workspaces(0).OpenDatabase("c:\path\Another.mdb")

    Just curious, but is there a difference between that and

    DBEngine.OpenDatabase()? I would assume the shorter version is going

    to use the default workspace, and have never used anything else.


    David W. Fenton                  http://www.dfenton.com/ contact via website only     http://www.dfenton.com/DFA/

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-11-08T19:10:18+00:00

    Thick Mike wrote:

    Is it possible to run Query_A in Database_A from Database_B?

    The best method depends on the type of the query.

    If it's an action query you can do it with a view lines of e.g. DAO code:

    Dim db As DAO.Database

    Set db = DBEngine.Workspaces(0).OpenDatabase("c:\path\Another.mdb")

    db.Execute "YourQueryNameInTheOtherDB", dbFailOnError


    cu

    Karl

    *******

    Access-FAQ (German/Italian): http://www.donkarl.com

    Was this answer helpful?

    0 comments No comments