Delete multiple tables from ms access 2000

I need to delete multiple tables from an access 2000 database using vbscript.

I have an issue with the database and it appears that it could be hundreds of temporary tables in the form of
Ztemp balance 20-2-2014, Ztemp balance 21-2-2014, etc and I want to get rid of the lot.

so I need a sql do delete en masse

delete TABLE where tablename LIKE "Ztemp" or what ever the correct nomenclature is

thanks in advance
markaleeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
It is easier to use VBA for this:
Public Function DeleteTables()

    Dim db  As DAO.Database
    Dim td  As DAO.TableDef
    
    Set db = CurrentDb
    
    For Each td In db.TableDefs
        If InStr(td.Name, "Ztemp balance") = 1 Then
            Debug.Print td.Name;
            db.TableDefs.Delete td.Name
            Debug.Print , " - deleted"
        End If
    Next
    
    Set td = Nothing
    Set db = Nothing
    
End Function

Open in new window

/gustav
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
Disclaimer: You may already do the following, for anyone else reading this post this may help.

TIP/Warning: Be sure to make a backup before you run any code that deletes!

Good database maintenance practice:
After deleting the tables , or any other data and other objects, make another back up and then run compact/repair the database.
markaleeAuthor Commented:
Public Function DeleteTables()

    Dim db  As DAO.Database
    Dim td  As DAO.TableDef
   
    Set db = CurrentDb
   
    For Each td In db.TableDefs
        If InStr(td.Name, "Ztemp balance") = 1 Then
            Debug.Print td.Name;
            db.TableDefs.Delete td.Name
            Debug.Print , " - deleted"
        End If
    Next
   
    Set td = Nothing
    Set db = Nothing
   
End Function


Probably may work, but I would have no idea how to implement the code, programming is not my field of work, beyond ASP and vbscript I have no knowledge, was hoping for something that I could just run in one of my existing vbscript files
Gustav BrockCIOCommented:
You can obtain a list of the tables:

SELECT MSysObjects.Name
FROM MSysObjects
WHERE MSysObjects.Type=1 AND MSysObjects.Name Like "Ztemp*";

Then you can create a loop calling this SQL for each table:

"DROP TABLE " & YourZtempTableName & ";"

/gustav

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.