VBA/Excel/Access/Word/Access/Table Delete
Deleting a Table from a Database
Sub Delete_Table()
Dim cat As ADOX.Catalog
On Error GoTo ErrorHandler
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
cat.Tables.Delete "vbexTable"
Set cat = Nothing
Exit Sub
ErrorHandler:
MsgBox "Table "" & "tblFilters" & _
"" cannot be deleted " & vbCrLf & _
"because it does not exist."
Resume Next
End Sub
Deleting a Table with SQL command
Sub DeleteTable()
Dim conn As ADODB.Connection
On Error GoTo ErrorHandler
Set conn = CurrentProject.Connection
conn.Execute "DROP TABLE myTable"
Application.RefreshDatabaseWindow
ExitHere:
conn.Close
Set conn = Nothing
Exit Sub
ErrorHandler:
If Err.Number = -2147217900 Then
DoCmd.Close acTable, "myTable", acSavePrompt
Resume 0
Else
Debug.Print Err.Number & ":" & Err.Description
Resume ExitHere
End If
End Sub