Details:
I have an MS-Access Database procedure where I create tables locally in the database. However, I want to ensure that the tables I create are tested for and if the test fails I need to delete/drop the other tables that have been created. Basically a rollback procedure I guess.
Question:
I came across the two methods to delete tables but cannot figure out if one has more pro than cons etc...
Can someone tell me what the difference is?
Many Thanks!
DoCmd.DeleteObject acTable, "aaaTest"
...and...
Dim cdb As DAO.Database
Set cdb = CurrentDb
cdb.Execute "DROP TABLE [aaaTest]", dbFailOnError
...and...
Dim cdb As DAO.Database
Set cdb = CurrentDb
cdb.TableDefs.Delete "aaaTest"
...are all just different ways of accomplishing the same thing. They delete the local TableDef
object with that name (either an actual local table, or a table link).
I just found out that DropTable doesn't like table names with a dash in them. I had quite a few, so I used DoCmd.Rename to rename the table right before I used droptable to erase them. This was the easiest fix for me because I had 15 table with dashes in them and 60 all together that I delete upon exit to clean up temporary files.