Solved

Change table link in MS Access using VBA

Posted on 2006-07-13
5
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

707 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