Option Compare Database
Option Explicit
Public Function GMRelink()
On Error GoTo Err_GMRelink
Dim DB As Variant
Dim Source As String, DataPath As String
Dim dbSource As String, i As Integer, j As Integer
Dim strNewDB As String
Dim strOldDB As String
Dim strNewServeur As String
Dim strOldServeur As String
Dim strOldName, strOldSource, strOldConnect, strNewSource, strNewConnect As String
Dim strOldAttributes As Long
Dim Temp As Object
strOldDB = "MDGSR."
strNewDB = "MDORA1A_20."
strOldServeur = ""
strNewServeur = ""
Set DB = DBEngine.Workspaces(0).Databases(0)
i = 0
While i <= DB.TableDefs.Count - 1
If Left(Trim(DB.TableDefs(i).connect), 4) = "ODBC" Then
Debug.Print DB.TableDefs(i).SourceTableName
If Left(Trim(DB.TableDefs(i).SourceTableName), Len(strOldDB)) = strOldDB Then
strOldName = DB.TableDefs(i).Name
strOldAttributes = DB.TableDefs(i).Attributes
strOldSource = DB.TableDefs(i).SourceTableName
strOldConnect = DB.TableDefs(i).connect
strNewSource = strNewDB & Mid(strOldSource, Len(strOldDB) + 1)
If strOldServeur <> "" And strNewServeur <> "" Then
strNewConnect = Replace(strOldConnect, strOldServeur, strNewServeur)
Else
strNewConnect = strOldConnect
End If
DB.TableDefs.Delete strOldName
Set Temp = DB.CreateTableDef(strOldName, 0, strNewSource, strNewConnect)
DB.TableDefs.Append Temp
Debug.Print Temp.SourceTableName
Else
i = i + 1
End If
Else
i = i + 1
End If
Wend
MsgBox "Terminé"
Exit Function
Err_GMRelink:
MsgBox "Erreur lors de la reconnection aux données. Vérifier le chemin dans DataPath.txt."
DoCmd.Quit
End Function
Public Function GetDataPath() As String
Dim AppPath As String
AppPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\"))
Open AppPath & "DataPath.txt" For Input As #1
Line Input #1, GetDataPath
Close #1
End Function