Delete Object Macro

S

sg

I have many tables in my database as a result of a make-table query. The
tables are named Data, Data1, Data2, etc. If there any way to use the Delete
Object action in a macro to delete all of the tables that start with "data"
regardless of the number behind them? I tried using the * (Wildcard) but it
didn't allow that.

Thanks in advance.
 
W

Wolfgang Kais

Hello "sg".

sg said:
I have many tables in my database as a result of a make-table query.
The tables are named Data, Data1, Data2, etc. If there any way to
use the Delete Object action in a macro to delete all of the tables
that start with "data" regardless of the number behind them?
I tried using the * (Wildcard) but it didn't allow that.

This will not work with a macro, you will have to use VBA. Add a
function like the following to a module:

Public Function DeleteTables(Pattern As String) As Boolean

Dim tbl As Object
For Each tbl In CurrentDb.TableDefs
If tbl.Name Like Pattern Then DoCmd.DeleteObject acTable, tbl.Name
Next

End Function

You can call the function from within a macro using the RunCode action,
using the argument DeleteTables("Data*")
 
S

sg

Thank you! This was so helpful!

Wolfgang Kais said:
Hello "sg".



This will not work with a macro, you will have to use VBA. Add a
function like the following to a module:

Public Function DeleteTables(Pattern As String) As Boolean

Dim tbl As Object
For Each tbl In CurrentDb.TableDefs
If tbl.Name Like Pattern Then DoCmd.DeleteObject acTable, tbl.Name
Next

End Function

You can call the function from within a macro using the RunCode action,
using the argument DeleteTables("Data*")

--
Regards,
Wolfgang


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top