Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Dim tbl As TableDef
Dim x As Long, MaxX As Long
Dim tblDB As String
Me.Visible = False
tblDB = myFolder & "Folder\Database.MDB"
If Dir(tblDB) = "" Then
MsgBox "No table database has been found, " & vbCr & vbCr & _
"This application will not work, so its beeing closed", vbCritical
Application.Quit
End If
MaxX = 1 ' first count all attached tables
For Each tbl In CurrentDb.TableDefs()
If tbl.Attributes = dbAttachedTable Then MaxX = MaxX + 1
Next tbl
x = 1 ' Now update them
For Each tbl In CurrentDb.TableDefs()
If tbl.Attributes = dbAttachedTable Then
tblDB = myFolder & Mid(tbl.Connect, InStr(1, tbl.Connect, "Folder\"))
If tbl.Connect <> ";Database=" & tblDB Then
Me.Visible = True
Me.Repaint
tbl.Connect = ";Database=" & tblDB
tbl.RefreshLink
End If
x = x + 1
End If
Me.Fill.Width = x / MaxX * Me.FillTo.Width
Next tbl
If Me.Visible Then
Me.lblWait.Caption = "Done relinking ... "
Me.Repaint
MaxX = Timer + 2
Do While Timer <= MaxX
Loop
End If
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, Me.Name
End Sub
Function myFolder()
myFolder = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\"))
End Function