Delete Object Macro

  • Thread starter Thread starter sg
  • Start date Start date
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.
 
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*")
 
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


.
 
Back
Top