How can a relative path specify a linked table in Access 2007?

前端 未结 6 653
抹茶落季
抹茶落季 2021-01-01 20:19

I have a front end and back end of an Access database. The front end references linked tables and I need to do a relative link instead of an explicit one i.e. \"../dat

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 21:10

    Here is a simple routine that worked for me:

    Public Function gbLinkTables() As Boolean
    On Error GoTo ErrorRoutine
    Dim sMyConnectString        As String
    Dim tdf                     As TableDef
    
        'We will link all linked tables to an accdb Access file located in the same folder as this file.
        'Replace the DATA file name in the following statement with the name of your DATA file:
        sMyConnectString = ";database=" & CurrentProject.Path & "\Loan-Tracking-Data.accdb"
        For Each tdf In CurrentDb.TableDefs
            If Len(tdf.Connect) > 0 Then
                'It's a linked table, so re-link:
                tdf.Connect = sMyConnectString
                tdf.RefreshLink
            End If
        Next tdf
    
    
    ExitRoutine:
        Exit Function
    ErrorRoutine:
        MsgBox "Error in gbLinkTables: " & Err.Number & ": " & Err.Description
        Resume ExitRoutine
    End Function
    

提交回复
热议问题