Thank you for your reply.
I'm using Access 2000, version 9.0.0.6620 and Jet version
4.0.7328.0
I will search the Knowledge Base to check out the Conect
Property you mention.
I will appreciate if you can have a look on the code I am
using for refreshing (I already add the Set xxx =
Nothing).
Thanks in advance.
Private Sub Form_Load()
'Link tables
On Error GoTo LinkTables_Err:
Dim strPath As String
Dim strDefaultPath As String
strDefaultPath = "I:\01\Drives\Data Bases"
DoCmd.Hourglass True
If Not VerifyLink Then
If Not ReLink(CurrentProject.FullName, True) Then
strPath = WinAPI.FileOpen(strDefaultPath)
If Not ReLink(strPath, False) Then
MsgBox "You cannot run this
Application without locating Data Tables"
DoCmd.Close acForm, "frmStartUp"
DoCmd.Quit
End If
End If
End If
DoCmd.Hourglass False
Salir_Sub:
Exit Sub
LinkTables_Err:
DoCmd.Hourglass False
MsgBox "Error " & Err.Number & ": " &
Err.Description
Resume Salir_Sub
End Sub
Function VerifyLink() As Boolean
On Error GoTo Err_Verify
'Verify connection information in linked tables
Dim cat As ADOX.Catalog
Dim tdf As ADOX.Table
Dim strTemp As String
Set cat = New ADOX.Catalog
With cat
Set .ActiveConnection = CurrentProject.Connection
'Continue if links are broken
On Error Resume Next
'open table to see if connection info is right
For Each tdf In .Tables
If tdf.Type = "LINK" Then
strTemp = tdf.Columns(0).Name
If Err.Number Then
Exit For
End If
End If
Next tdf
End With
VerifyLink = (Err.Number = 0)
Salir_Fun:
On Error Resume Next
Set cat = Nothing
Set tdf = Nothing
Exit Function
Err_Verify:
MsgBox "Error " & Err.Number & ": " &
Err.Description
Resume Salir_Fun
End Function
Function ReLink(strDir As String, DefaultData As Boolean)
As Boolean
On Error GoTo ReLink_Err
'Relink a broken linked table
Dim cat As ADOX.Catalog
Dim tdfReLink As ADOX.Table
Dim oDBInfo As DBInfo
Dim strPath As String
Dim strName As String
Dim intCounter As Integer
Dim vntStatus As Variant
vntStatus = SysCmd(acSysCmdSetStatus, "Updating Links")
Set cat = New ADOX.Catalog
Set oDBInfo = New DBInfo
With cat
.ActiveConnection = CurrentProject.Connection
oDBInfo.FullName = strDir
strPath = oDBInfo.FilePathOnly
strName = Left(oDBInfo.FileName, InStr
(oDBInfo.FileName, ".") - 1)
On Error Resume Next
Call SysCmd(acSysCmdInitMeter, "Linking
DataTables", .Tables.Count)
For Each tdfReLink In .Tables
intCounter = intCounter + 1
Call SysCmd(acSysCmdUpdateMeter,
intCounter)
If .Tables(tdfReLink.Name).Type
= "LINK" Then
tdfReLink.Properties("Jet
OLEDB:Link Datasource") _
= strPath & strName & IIf
(DefaultData, "Data.Mdb", ".mdb")
End If
If Err.Number Then
Exit For
End If
Next tdfReLink
End With
Call SysCmd(acSysCmdRemoveMeter)
vntStatus = SysCmd(acSysCmdClearStatus)
ReLink = (Err = 0)
Salir_Sub:
On Error Resume Next
Set cat = Nothing
Set tdfReLink = Nothing
Set oDBInfo = Nothing
Exit Function
ReLink_Err:
MsgBox "Error " & Err.Number & ": " &
Err.Description
Resume Salir_Sub
End Function