Solved

Change table link in MS Access using VBA

Posted on 2006-07-13
5
273 Views
Last Modified: 2010-04-30
I know how to get the link from a table to a table in another database, but I don't know how to change it.  Example, a table links to a table in "C:\Data\Old\Database.mdb" and I want it changed to "D:\Data\New\Database.mdb".  Due to the number of tables & links involved, I need it done via code instead of the manual process.  It would have to be looped for each table found in a database without having to specify the table (link) names.

There is a rush on this question, so I give 500 points.

0
Comment
Question by:CCIG2006
  • 3
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17098427
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17098641
try this


Public Sub ListMyTables()

    Dim db As DAO.Database
    Dim tbl As TableDef
    Dim sOldPath As String
    Dim sNewPath As String
   
    sOldPath = "C:\Data\Old\Database.mdb"
    sNewPath = "D:\Data\New\Database.mdb"
   
    Set db = CurrentDb
    For Each tbl In db.TableDefs
        'if table has a connect string, check its contains oldpath then replace with newpath
        If Len(tbl.Connect) > 0 Then
            Debug.Print tbl.Name, tbl.Attributes, tbl.SourceTableName, tbl.Connect
            If InStr(1, tbl.Connect, sOldPath) > 0 Then
                tbl.Connect = Replace(tbl.Connect, sOldPath, sNewPath)
                tbl.RefreshLink
            End If
        End If
    Next tbl
End Sub

0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17098953
0
 

Author Comment

by:CCIG2006
ID: 17100386
Awesome!  Thanks!!!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17106642
No probs
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write data from SQL to CSV file - position 1 61
Passing a Text Box name to a Sub 6 96
fso.FolderExists("\\server\HiddenFolder$") 4 66
vbModal 12 53
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question