Ever needed to delete the linked tables out of your database. Sadly Access does not allow one to make multiple selection of Access object to perform batch actions on, such as delete. So if you have quite a few tables to delete it can be frustrating and a waste of time. This is why I create the very simply procedure found below.
'---------------------------------------------------------------------------------------
' Procedure : DeleteAttachedTbls
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Deletes all the linked tables from the active database. It only removes
' the links and does not actually delete the tables from the back-end
' database.
' Copyright : The following may be altered and reused as you wish so long as the
' copyright notice is left unchanged (including Author, Website and
' Copyright). It may not be sold/resold or reposted on other sites (links
' back to this site are allowed).
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2011-06-10 Initial Release
' 2 2020-04-09 Code change based on Ben Sacherich's comment
'---------------------------------------------------------------------------------------
Function DeleteAttachedTbls()
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim tdf As DAO.TableDef
DoCmd.SetWarnings False
Set db = CurrentDb()
For Each tdf In db.TableDefs
If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Then
'DoCmd.DeleteObject acTable, tdf.Name
db.TableDefs.Delete tdf.Name 'Per Ben Sacherich's recommendation
End If
Next
Error_Handler_Exit:
DoCmd.SetWarnings True
Set tdf = Nothing
Set db = Nothing
Exit Function
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: DeleteAttachedTbls" & vbCrLf & _
"Error Description: " & Err.Description, _
vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Function