Changing the linked table path without the linked table manager 
Author Message
 Changing the linked table path without the linked table manager

I am trying to programmatically alter the location of my linked files. I
thought that the code below would do the trick, but when I execute it and
then look again at the links using the linked table manager, I see that the
connect property has not changed. Does anybody know what I am doing wrong ?

Sub ChangeListPath()
    Dim Td As TableDef
    CurrentDb.TableDefs.Refresh
    For Each Td In CurrentDb.TableDefs    'for each table
        If CurrentDb.TableDefs(Td.Name).Connect <> "" Then    ' if it is a
linked table
            CurrentDb.TableDefs(Td.Name).Connect = ";DATABASE=C:\db2.mdb"
        End If
    Next
End Sub

Sincerely
Jan Vereecke



Sun, 06 Jun 2004 00:20:37 GMT  
 Changing the linked table path without the linked table manager
Hi Jan
Two things.
1. Alias your database. Avoids some hassles (some that you're experiencing -
possibly unwittingly) and is good practice. CurrentDB refreshes every object
every time it's called. You need to get a handle on the object - do not get
a new handle each time with "dbCurrent.TableDefs(Td.Name)", or
CurrentDB.TableDefs(Td.Name)", etc

    Dim dbCurrent As Database
    Set dbCurrent = CurrentDB()

2. Modify code as follows (If you already have the handle to Td why not use
it?).

    For Each Td In dbCurrent.TableDefs()
        If Td.Connect <> "" Then
            Td.Name.Connect = ";DATABASE=C:\db2.mdb"
            Td.Refresh    ' **    This causes link property to be updated.
        End If
    Next
--
Graeme Richardson
Analyst Programmer
AdeptX Limited



Sun, 06 Jun 2004 02:10:24 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Linked table manager to be changed from (X:\) a server drive to (C:\) a local machine

2. Linked tables - changing the link

3. Changing Linked Table link?

4. How to change linked table path...

5. Changing path to linked table

6. Changing Access Linked Tables Source Path

7. Changing a linked table path at runtime

8. Link Table manager

9. How do you open the link table manager.

10. linked table manager

11. MSysObjects and Linked Table Manager

12. 97 Linked Table Manager brings up A2k Windows Installer

 

 
Powered by phpBB® Forum Software