I'm working on an Access 365 app for a client. At their office their tables are linked to a back end database. When I copy the app to my PC I need to relink the tables to the DB on my PC.

I have written this code:

Code:
Public Sub LinkTablesLocal()

    Dim computerName As String
    computerName = Environ("computername")

Stop

    If computerName = "MY_PC" Then
    
        Dim databaseFile As String
        Dim dbs As DAO.Database
        Dim tdf As DAO.TableDef
        Dim tableName As String
        Set dbs = CurrentDb()
        
        databaseFile = CurrentProject.Path & "\MyApp.accdb"
        
        For Each tdf In dbs.TableDefs
        
            If Len(tdf.Connect) > 1 Then
            
                If tdf.Connect <> ";DATABASE=" & databaseFile Then
                    
                    If Left(tdf.Connect, 4) <> "ODBC" Then
                    
                        tableName = tdf.Name
                        dbs.TableDefs(tableName).Connect = ";DATABASE=" & databaseFile
                        dbs.TableDefs(tableName).RefreshLink
                        
                    End If
                    
                End If
                
            End If
            
        Next tdf

    End If

End Sub
The code fails on the RefreshLink command with "The Microsoft Access database engine cannot find the input table or query 'tblAudit'. Make sure it exists and that its name is spelled correctly."

The table 'tblAudit' does exist in the database.

First, is this the right way to do this? If so, what's wrong here?

Many thanks