Solved

Change table link in MS Access using VBA

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

18 Experts available now in Live!

Get 1:1 Help Now