Private Sub cmdImport_Click()
On Error GoTo Err_cmdLinkTables_Click
Dim strFileName, strTableName, strImport As String
strFileName = PromptFileName()
If strFileName = "" Then
Exit Sub
End If
strImport = MsgBox("Importing data from selected file, will delete all data in current file. Please confirm?", vbYesNo, "Confirm data import")
If strImport = 6 Then
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllTables collection.
For Each obj In dbs.AllTables
strTableName = obj.Name
'Some other objects in the .AllTables Collection are not tables
If Not (Left(strTableName, 4) = "MSys") Then
'1. Delete the current link
DoCmd.DeleteObject acTable, strTableName
'This MsgBox was used to debug. Comment out or delete as you like
'2. Re-Link the table
'MsgBox "Linking " & strTableName & "."
DoCmd.TransferDatabase acImport, "Microsoft Access", strFileName, _
acTable, strTableName, strTableName
End If
Next obj
ElseIf strImport = 5 Then
Exit Sub
End If
Exit_cmdLinkTables_Click:
Exit Sub
Err_cmdLinkTables_Click:
MsgBox Err.Description
Resume Exit_cmdLinkTables_Click
End Sub