Question : VBA to delete a specific series of Access tables

I have an Access database with following list of tables:

tblType1Apple
tblType1Pear
tblType2Cabbage
tblType3Car


I looking for a block of VBA code that will drop (remove) ALL tables in my database that start with "tblType1".  
Notice I want to "drop" the table as opposed to "delete" the table.  In SQL terms it would be something like this:

1:
2:
3:
4:
5:
6:
Sub DropTables()
With DoCmd
  .RunSQL "DROP TABLE tblType1Apple"
  .RunSQL "DROP TABLE tblType1Pear"
End With
End Sub


Maybe I declare a variable that specifies what the table name will start with and the code will match that to all tables in the database, loop through, and drop the corresponding table???  Any ideas are greatly appreciated.  Thanks as always.


Answer : VBA to delete a specific series of Access tables

use the tabledef

dim td as dao.tabledef, db as dao.database
set db=currentdb

for each td in db.tabledefs
    if left(td.name, 8)="tblType1" then
        db.execute "drop table ["& td.name &"]"
    end if
next
Random Solutions  
 
programming4us programming4us