Connection between 2 databases

I have 3 Access databases using similar modules.
For easing the maintenance of the modules, I would like to locate the modules in one database and to use those modules in the 2 other databases.
Is it feasible?
Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor PresidentCommented:
Yes.   You place the code in a DB, rename it with a MDA  extension (not absolutly required, it's just a convention).

Then in each DB, you set a reference in VBA to the MDA DB.

You can then call code in the MDA as if it resided in your DB.   Note that if you make a change in the MDA code, you need to re-compile your DB code.

Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Also should add that these are referred to as "Library" DB's and you should be aware of CurrentDB() vs CodeDB().

Depending on the operations you are performing, it may be important to know where the code is executing.  

See the on-line help for CodeDB() for all the details.

SommerAlainAuthor Commented:
Hi Jim, Thank you it looks clear. I will see it later today. I mainly use sql code. Is there somthing specific?
Have a nice day
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Jeffrey CoachmanMIS LiasonCommented:
Also what some Access developers do is simply store all their "useful" codes in one simple text file

The code in your MDA file should only contain the code needed for that particular system

SommerAlainAuthor Commented:

In DataBase A I have a sub like this one:

Private Sub CalculateXXS
Call CalculateComplex("TableLocalTable")
End Sub

Imagine that the code of the sub CalculateComplex is in DataBase B and that the TableLocalTable is in DataBase A.
How to adapt this code to make it work?

Best regards
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
In this case, there is nothing you would need to do.  When you need to use CodeDB() is if your code is referring to objects in the library DB.

CurrentDB() always points to the DB open in the Access interface.  CodeDB() may or may not be different depending on the procedure that is currently executing and where it is.

This is actually how all the Access Wizards are written that you use, and things like the F2 Zoom Box.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.