I’m trying to delete two tables that I import into a 2016 Access database regularly to update other program tables in a program using a VBA code behind an “On Click” [Event Procedure] command button in a form that keeps returning a “Run-time error 2387. You can’t delete the table ‘tbl_(Master_Oil_Sample_Data)1; it is participating in one or more relationships.”
Option Compare Database
Private Sub Command35_Click()
DoCmd.RunSavedImportExport "Import_Data_001"
Beep
MsgBox "Your request to update your tables data has been completed using another MS Access Database file!""", vbInformation, "All rights reserved Copyright © 2019 - 2020, Michael Eisner"
End Sub
Private Sub Command41_Click()
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Interp_Data)1"
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Data)1"
Beep
MsgBox "Your request to delete imported tables has been completed!""", vbInformation, "All rights reserved Copyright © 2019 - 2020, Michael Eisner"
End Sub
Private Sub Form_Close()
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Interp_Data)1"
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Data)1"
Beep
MsgBox "Temporary imported tables have been completed!""", vbInformation, "All rights reserved Copyright © 2019 - 2020, Michael Eisner"
End Sub
- When I checked these two tables with a 1 at the end of the table name, do have Relationships assigned to them during the import process, just like the program tables that have the same name, the only difference is that they are automatically assigned a 1 at the end of their names.
- But when I highlight these two tables and try to delete them manually, I get the following MS Access warning: “Do you want to delete all of the selected objects? Deleting these objects will remove them from all groups.” You cannot undelete forms, reports, and modules.” I press <Yes>, and they're gone.
- Is there a better way to delete these two imported tables using VBA code so that I do not get the error?
Option Compare Database
Private Sub Command35_Click()
DoCmd.RunSavedImportExport "Import_Data_001"
Beep
MsgBox "Your request to update your tables data has been completed using another MS Access Database file!""", vbInformation, "All rights reserved Copyright © 2019 - 2020, Michael Eisner"
End Sub
Private Sub Command41_Click()
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Interp_Data)1"
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Data)1"
Beep
MsgBox "Your request to delete imported tables has been completed!""", vbInformation, "All rights reserved Copyright © 2019 - 2020, Michael Eisner"
End Sub
Private Sub Form_Close()
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Interp_Data)1"
DoCmd.DeleteObject acTable, "tbl_(Master_Oil_Sample_Data)1"
Beep
MsgBox "Temporary imported tables have been completed!""", vbInformation, "All rights reserved Copyright © 2019 - 2020, Michael Eisner"
End Sub