Refreshing links refers to updating the link to an external table. It is done when the location of an external table has changed.
Removing links refers to permanently removing a link to an external table.
Access cannot find external tables if their locations have moved. You need to adjust for this in your VBA code. Furthermore, there might be times when you want to remove a link to external datawhen it is no longer necessary to use the data, or when you have permanently imported the data into Access.
To refresh a link using VBA code, simply redefine the Jet OLEDB:Link Datasource. Listing 19.10 shows the code to refresh a link.
You can modify this routine to prompt the user for the directory containing the data tables, as Listing 19.11 shows.
This routine points a Table object to the tblClients table. It then attempts to access the name of the first column in the table. If an error occurs, an input box prompts the user for the new location of the database. The routine modifies the Jet OLEDB:Link Datasource property for the database to incorporate the new location. It then resumes on the offending line of code. You should modify this routine to give the user a way out. Resume throws the user into an endless loop if the database is not available. An enhanced routine (see Listing 19.13) is presented later in the "Practical Examples" section of this chapter.
To remove a link using VBA code, simply execute a Delete method of the Tables collection of a Catalog object connected to the database, as shown in Listing 19.12.
New to Access 2003 is the capability to convert a linked table to a local table. The process works like this:
Click to select Tables in the list of objects.
Click to select the linked table that you want to convert to a local table.
Select Edit, Copy.
Select Edit, Paste. The Paste Table As dialog appears (see Figure 19.10).
Type a name for the new table.
Select Structure and Data to copy both the structure of the linked table and its data, or select Structure to copy only the structure of the linked table.
Click OK.
The linked table now appears as a local table within the current database.