Microsoft Access 2010 Bible

(Rick Simeone) #1

Part III: More-Advanced Access Techniques


600


FIGURE 16.13
The Linked Table Manager enables you to relocate external tables that have been
moved.

Note
If the Linked Table Manager Wizard is not present on your computer, Access automatically prompts you to
provide the original Office CD so that Access can install the wizard. This may happen if you didn’t instruct
Office to install the Additional Wizards component during the initial installation process.


Using Code to Link Tables in Access


This section describes how to link tables to your Access application in code, instead of using the
Access menus. It would be nice if you could just make the link once at development time and be
done with the whole process. Occasionally, however, you might want to attach tables on the fly, to
avoid losing a link. Testing your links whenever your application starts is a good practice — that
way, you can keep users from facing any crashes or error messages. You’ll find some examples of
these routines in this section.

Note
The following code examples use DAO instead of ADO. For purposes such as linking tables, DAO works con-
siderably faster than ADO, and is simpler to implement. The reason DAO is faster than ADO for simple opera-
tions such as linking tables is because DAO doesn’t involve the overhead associated with declaring,
instantiating, and discarding ActiveX controls. Because DAO is a much simpler object model, you’ll find DAO
is, arguably, a better fit for simple operations such as linking tables, although ADO might be a better choice for
complex data management operations.


The Connect and SourceTableName properties
Open Chapter16.accdb and press Ctrl+G to open the Immediate window. Then, in the
Immediate pane of the Immediate window, type the following:

? CurrentDB.TableDefs(“tblContacts”).Connect
Free download pdf