Purpledawn,
My personal preference is to not delete tables but to empty them. I find it easier to follow code and queries if the worktables are intact. Also you may need to trim you list of tables to delete due to some of them being linked tables, or they may be "Reference Tables" ie:
XRef Tables that store a master list of items to process,
of "if this = this , substitute this thing" type stuff.
With that said here is what I did:
Both functions are run with a Call
Hope they work
RGB
'The first function will check for any "Valid" tables to empty. It is intended
'to catch all temp files, but it's a good idea to check the master table before
'running the Empty Function. After the "Valid" tables are selected you will be
'prompted to edit the table before emptying begins
Public Function GetTablesToDelete()
Dim ThisDatabase As Database
Set ThisDatabase = CurrentDb
DoCmd.SetWarnings False
'The following SQL Statement reads MSysObjects and identifies tables in the
'database that may be candidates for emptying. Candidates are generally local
'tables that are not being used as Access reference table and tables that are not linked.
DoCmd.RunSQL ("SELECT MSysObjects.Name AS table_name INTO XXX_wrkfl_0000_tables_to_empty FROM MSysObjects WHERE (((MSysObjects.Name) Not Like 'XXX*') AND ((MSysObjects.Flags)=0) AND ((MSysObjects.Type)=1)); "
'The following Message Box just states that there may be files that shouldn't be emptied
'then opens the "Master" table for verification.
MsgBox "After the table opens, check for Tables (Reference Tables)" & Chr(13) & "that you do not want emptied. To delete the ""Table""(record), " & Chr(13) & "just select it in the table and delete it!"
'Opens the "Master" table for viewing
DoCmd.OpenTable "XXX_wrkfl_0000_tables_to_empty"
DoCmd.SetWarnings True
End Function
Public Function EmptyTables()
Dim ThisDatabase As Database
Set ThisDatabase = CurrentDb
Dim TablesToEmpty As Recordset
Set TablesToEmpty = ThisDatabase.OpenRecordset("XXX_wrkfl_0000_tables_to_empty"

Dim TableName As String
Dim NumberOfTablesToDelete As Double
DoCmd.SetWarnings False
'This section cycles through the "Master" table and empties all tables listed
'Please note: some tables may cause an error because the name doesn't conform
'with an SQL Statement
'The following two lines are used if you want to have a "Last Chance" at
'changing your mind. They just count the number of tables you are going
'to delete and asks if you want to continue. "Un Rem" to make active.
'NumberOfTablesToDelete = DCount("*", "XXX_wrkfl_0000_tables_to_empty"

'If MsgBox("You are about to empty " & NumberOfTablesToDelete & " Table(s)." & Chr(13) & "Do you wish to continue?", vbYesNo, "The Table Killer !!"

= vbNo Then Exit Function
TablesToEmpty.MoveFirst
Do
TableName = TablesToEmpty!table_name.Value
DoCmd.RunSQL ("DELETE " & TableName & ".* FROM " & TableName & "; "

TablesToEmpty.MoveNext
Loop Until TablesToEmpty.EOF
DoCmd.SetWarnings True
End Function