Solved

Change table link in MS Access using VBA

Posted on 2006-07-13
5
262 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now