ggregg said:
Is there any way to use code to delete all the Linked Tables?
Thank you
ggrep,
the short answer is Yes!
the longer answer is modify the code below. This code is launched from the
OnOpen event of a main form. Obviously there are lines that would not be
applicable to your situation, you NEED to review the code and modify it for
your purposes. The salient line is:
DoCmd.DeleteObject acTable, tdf.Name
Dan Knight
Begin Code:
Public Sub CheckLinkedTables()
Dim intTableCount As Integer, intCounter As Integer
On Error Resume Next
DoCmd.OpenForm "frmSplashScreen", acNormal
Set dbs = CurrentDb()
strPath = Application.CurrentProject.Path & "\data\"
'MsgBox strPath
'MsgBox "The current database is located at " &
Application.CurrentProject.Path & "."
With dbs
intTableCount = .TableDefs.Count
intCounter = 0
For Each tdf In .TableDefs
intCounter = intCounter + 1
strProgress = "Checking table " & tdf.Name
If tdf.Attributes = dbAttachedTable Then '(tdf.Name Like "MSys*"
Or tdf.Name = "LinkLocation") Then ' Or tdf.Name = "User") Then
If tdf.Connect <> "" Then
' MsgBox tdf.Name & " is linked" & vbCr & vbCr &
tdf.Connect
strConnectPath = tdf.Connect
strConnectPath = Right(strConnectPath,
Len(strConnectPath) - InStr(1, strConnectPath, "="))
Do While Right(strConnectPath, 1) <> "\"
strConnectPath = Left(strConnectPath,
Len(strConnectPath) - 1)
Loop
If strConnectPath <> strPath Then
DoCmd.DeleteObject acTable, tdf.Name
DoCmd.TransferDatabase acLink, "Microsoft
Access", strPath & "PIMSBackEnd.mdb", acTable, tdf.Name, tdf.Name, False
strProgress = "Linking table " & tdf.Name
End If
End If
End If
SetPMeter Forms("frmSplashScreen"), intCounter /
intTableCount, strProgress
Next tdf
End With
DoCmd.Close acForm, "frmSplashScreen", acSaveNo
End Sub