Results 1 to 3 of 3
  1. #1
    alberigo67 is offline Novice
    Windows 7 64bit Office 365
    Join Date
    May 2020
    Posts
    8

    Check Link to DB tables and re-link

    Hi to everyone.


    I have a DB consist of two files, one with the front end forms and the other with all the tables.
    I need to create a procedure with VBA code that checks the links to the tables and eventually relink all of them to the front end file.
    Any suggestions?

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Why do you need relink? Check the links for what?

    Here's a start:
    Code:
    Public Sub SetTableLinks()
    'Relink tables with UNC pathing
    'Use the variables provided to do the manipulations desired
    Dim td As TableDef
    Dim db As DAO.Database
    Dim strOld As String
    Dim strNew As String
    'replace the following strings as needed
    'strOld = "R:\Lab\Database\Data\LabData.accdb"
    strOld = "C:\Users\June\DOT\Lab\Data\LabData.accdb"
    strNew = "C:\Users\Owner\June\DOT\Lab\Data\LabData.accdb"
    Set db = CurrentDb
    For Each td In db.TableDefs
        If InStr(td.Connect, strOld) > 0 Then
            Debug.Print td.Name
            Debug.Print "Old Link: " & td.Connect
            td.Connect = Replace(td.Connect, strOld, strNew)
            td.RefreshLink
            Debug.Print "New Link: " & td.Connect
        End If
    Next td
    db.TableDefs.Refresh
    End Sub
    

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I used a table rather than hard coding the value. That way if they changed the server name, or we got absorbed by a different business unit (which happened a few times). It's easier to update a table IMHO rather than having to modify and redistribute front ends.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-07-2019, 08:04 PM
  2. Replies: 1
    Last Post: 06-22-2017, 09:30 PM
  3. check, create and link a table in BE?
    By Frits1969 in forum Access
    Replies: 1
    Last Post: 04-21-2016, 02:34 AM
  4. Replies: 17
    Last Post: 09-02-2015, 09:05 PM
  5. Replies: 7
    Last Post: 08-28-2013, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums