O
online.experiment
Hello together,
I got this wonderful code from the internet to relink all tables from
a backend database in the same folder.
Unfortunatelly its not working: The code gets me the right folder (see
MsgBox (strPath) but after that it links only the first table but not
the others.
Can anybody tell me what's wrong in the code?
Thank you very much!!!
Andreas
Function link()
On Error GoTo MyError
Dim db As DAO.Database
Dim strPath As String
Dim i As Integer
Set db = CurrentDb()
strPath = Left(db.Name, Len(db.Name) - Len(Dir(db.Name))) &
"social_performance_be.mdb"
MsgBox (strPath)
MsgBox (db.TableDefs.Count)
For i = 0 To db.TableDefs.Count - 1
If db.TableDefs(i).Connect <> "" Then
If Mid(db.TableDefs(i).Connect, 11) <> strPath Then
db.TableDefs(i).Connect = ";database=" & strPath
db.TableDefs(i).RefreshLink
End If
End If
Next i
MsgBox ("all ok")
MyExit:
Exit Function
MyError:
MsgBox "Error during linking. ", 16, "Ausnahme"
Resume MyExit
End Function
I got this wonderful code from the internet to relink all tables from
a backend database in the same folder.
Unfortunatelly its not working: The code gets me the right folder (see
MsgBox (strPath) but after that it links only the first table but not
the others.
Can anybody tell me what's wrong in the code?
Thank you very much!!!
Andreas
Function link()
On Error GoTo MyError
Dim db As DAO.Database
Dim strPath As String
Dim i As Integer
Set db = CurrentDb()
strPath = Left(db.Name, Len(db.Name) - Len(Dir(db.Name))) &
"social_performance_be.mdb"
MsgBox (strPath)
MsgBox (db.TableDefs.Count)
For i = 0 To db.TableDefs.Count - 1
If db.TableDefs(i).Connect <> "" Then
If Mid(db.TableDefs(i).Connect, 11) <> strPath Then
db.TableDefs(i).Connect = ";database=" & strPath
db.TableDefs(i).RefreshLink
End If
End If
Next i
MsgBox ("all ok")
MyExit:
Exit Function
MyError:
MsgBox "Error during linking. ", 16, "Ausnahme"
Resume MyExit
End Function