[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Change table link in MS Access using VBA

Posted on 2006-07-13
5
Medium Priority
?
323 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
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…
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…
Suggested Courses

650 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