So how can you run a query in another database?
Well, that depends! It depends on whether you simply need to run an action query or if you actually wish to get the results returned to you.
One method is to use DAO programming to access the remote db and simply execute the query. This implies that you are simply wanting to run an action query.
Dim db As DAO.Database Set db = DBEngine.Workspaces(0).OpenDatabase("FullPathAndFileNameOfThe2ndDb") db.Execute "TheQueryNameYouWishToExecute", dbFailOnError Set db = Nothing
Another method which will actually return the results of a SELECT query… is to add the 2nd database as a reference in your 1st database and then call a function which open you query. You can find a sample database illustrating this technique at http://www.access-programmers.co.uk/forums/showthread.php?t=156716 (in the second post by MStef).

Monday, November 8th, 2010, 8:00 pm | 

