MS Access - How to change the linked table path by amend the table

前端 未结 1 1050
醉话见心
醉话见心 2021-01-14 06:24

Below query allow me to show all linked table and its corresponding database path

SELECT DISTINCTROW msysobjects.Name, msysobjects.Database, msysobjects.Conn         


        
相关标签:
1条回答
  • 2021-01-14 07:23

    Yes, you can either do it through VBA, or through the GUI

    Through the GUI (Access 2010):

    You can use the following VBA sub to change the connection strings on certain tables (you need to provide both the old and new connection string):

    Public Sub ChangeConnection(OldStr As String, NewStr As String)
        Dim td As DAO.TableDef
        Dim db As DAO.Database
        Set db = CurrentDb()
        For Each td In db.TableDefs
            With td
                If .Connect = OldStr Then
                    .Connect = NewStr
                    .RefreshLink
                End If
            End With
        Next td
    End Sub
    

    Or, you can use the following sub to change one specific table

    Public Sub ChangeTableConnection(Tablename As String, NewStr As String)
        Dim td As DAO.TableDef
        Dim db As DAO.Database
        Set db = CurrentDb()
        Set td = db.TableDefs(Tablename)
        td.Connect = NewStr
        td.RefreshLink
    End Sub
    
    0 讨论(0)
提交回复
热议问题