PDA

View Full Version : Solved: If Statement to say If Form Does not Exist Delete Table



jo15765
12-28-2011, 07:08 AM
I have a database with over 1000 forms, and over 1000 tables. I am trying to clean it up, and cut down on the manual labor. The form is named, frm_Test1234 and the corresponding table is named tbl_Test1234. I have been going through deleting forms, and now I am curious if instead of likewise having to delete tables as well, is there a function or sub that could be written that checks each table in the database, and if there is no form named the same then delete the linked table? So basically if I had deleted frm_test1234...when it was checking the tables, when it reached tbl_Test1234 access see's that frm_test1234 does not exist then it would delete tbl_test1234

Movian
12-28-2011, 09:36 AM
the following sub will loop through all forms in a DB as the object frm...
you could possible dim a second object called tbl and try to open it with the form name (presuming your tables share the same name as the form). If it errors then delete the form ? or Vica Versa as needed

Dim frm As AccessObject

For Each frm In CurrentProject.AllForms
'CODE HERE
Next