Gutanoth
Gutanoth

Reputation: 842

Drop all tables with <String> in their name

I am looking for a function or sub (in a module) wich I can call to drop all tables that have "tbl" in their name. I have found several pieces of code that just don't work right.


To clarify my question:

I am working in Access. In my project, I use VBA to generate a few tables. I don't know what the names of these tables will be beforehand. I do know that the tables that I would like to delete ("DROP") have "tbl" in their name.

What I am looking for is code that does something like this:

DoCmd.runSQL (DROP ALL TABLE LIKE '%tbl%')

I know this code does not work, but it should give a little insight in what I would like to achieve

Upvotes: 0

Views: 4888

Answers (1)

LS_ᴅᴇᴠ
LS_ᴅᴇᴠ

Reputation: 11181

I don't have "access to Access" right now, but you may create a macro, something like:

Sub Delete_tbl
    Dim t as TableDef
    For Each t In CurrentDB.TableDefs
        If t.Name Like "tbl*" Then DoCmd.runSQL("DROP TABLE " & t.Name)
    Next
End Sub

Upvotes: 5

Related Questions