J
John Ortt
I have a chunk of code which changes the links in a database to a new
folder.
The problem is that the "tbl.RefreshLink" produces an error if the new
location does not exist at the time of changing the link.
I wish to force the tables to relink to the non-existent database without
bringing up errors during the code.
I tried simply deleting the "tbl.RefreshLink" line but it doesn't update the
link location then.
Any help will be greatly appreciated, Thanks in advance,
John
Code Follows
////////////////////
Option Compare Database
Option Explicit
Function change_linksBreak()
Dim db As DAO.DATABASE
Dim tbl As DAO.TableDef
Dim oldBE As String
Dim newBE As String
Dim i As Integer
Dim tbln As String
Dim lnk As String
Set db = CurrentDb()
oldBE = "H:\Access\Local\New Folder\2\DATABASE.mdb"
newBE = "H:\DATABASE.mdb"
For i = 0 To db.TableDefs.Count - 1
tbln = db.TableDefs(i).Name
Set tbl = db.TableDefs(tbln)
lnk = tbl.Connect
If Left(lnk, 9) = ";DATABASE" Then
lnk = Replace(lnk, oldBE, newBE)
tbl.Connect = ""
tbl.Connect = lnk
' tbl.RefreshLink
End If
Next
End Function
Function Replace(ByVal Valuein As String, ByVal WhatToReplace As
String, ByVal Replacevalue As String) As String
Dim Temp As String, P As Long
Temp = Valuein
P = InStr(Temp, WhatToReplace)
Do While P > 0
Temp = Left(Temp, P - 1) & Replacevalue & Mid(Temp, P +
Len(WhatToReplace))
P = InStr(P + Len(Replacevalue), Temp, WhatToReplace, 1)
Loop
Replace = Temp
End Function
folder.
The problem is that the "tbl.RefreshLink" produces an error if the new
location does not exist at the time of changing the link.
I wish to force the tables to relink to the non-existent database without
bringing up errors during the code.
I tried simply deleting the "tbl.RefreshLink" line but it doesn't update the
link location then.
Any help will be greatly appreciated, Thanks in advance,
John
Code Follows
////////////////////
Option Compare Database
Option Explicit
Function change_linksBreak()
Dim db As DAO.DATABASE
Dim tbl As DAO.TableDef
Dim oldBE As String
Dim newBE As String
Dim i As Integer
Dim tbln As String
Dim lnk As String
Set db = CurrentDb()
oldBE = "H:\Access\Local\New Folder\2\DATABASE.mdb"
newBE = "H:\DATABASE.mdb"
For i = 0 To db.TableDefs.Count - 1
tbln = db.TableDefs(i).Name
Set tbl = db.TableDefs(tbln)
lnk = tbl.Connect
If Left(lnk, 9) = ";DATABASE" Then
lnk = Replace(lnk, oldBE, newBE)
tbl.Connect = ""
tbl.Connect = lnk
' tbl.RefreshLink
End If
Next
End Function
Function Replace(ByVal Valuein As String, ByVal WhatToReplace As
String, ByVal Replacevalue As String) As String
Dim Temp As String, P As Long
Temp = Valuein
P = InStr(Temp, WhatToReplace)
Do While P > 0
Temp = Left(Temp, P - 1) & Replacevalue & Mid(Temp, P +
Len(WhatToReplace))
P = InStr(P + Len(Replacevalue), Temp, WhatToReplace, 1)
Loop
Replace = Temp
End Function