I've got two Access databases that share linked tables. They are deployed together in a directory and accessed via code in a Word form.
How can I make sure that the links are preserved when the two databases are copied (together) to a different folder? Since I'm not "opening" the database, per se (it's being accessed via ADO), I don't know how to write code to refresh the links.
Update 14APR2009 I found that the previous answer I gave here was erroneous, so I updated it with new code.
How to proceed
From code or from the Immediate window in the VBA IDE, simply type:
This will now relink all the linked tables to use the directory where your application is located.
It only needs to be done once or whenever you relink or add new tables.
I recommend doing this from code every time you start your application.
You can then move your databases around without problems.
Code
This code is adapted from this source: http://www.mvps.org/access/tables/tbl0009.htm.
I removed all dependency on other functions to make it self-contained, that's why it's a bit longer than it should.
Are you referring to updating the links within your Word form, or the linked table links between your Access databases?
For the former, the best way that I know is to keep your connection string(s) at the Module level within your Word document/VBA project and make them const strings. Then when setting the connection string for your ADO Connection objects, pass it the relative connection string const.
For the latter, I would be tempted to use a relative path in the connection string to data within each Access database to the other. For example,
if as you say, the databases are copied together to a different folder (I'm assuming into the same folder).
Renaud's answer no longer works in Access 2010 with Excel or CSV files.
I have made a few modifications:
Here is the code:
I am unfortunately still on Access 2007. I started with one of the code blocks above which was not working for me. Having less access vba power I simplified it to only the first loop which gets the table paths and updates it in place. The next guy running into this can comment or update.
Option Compare Database