PC Review


Reply
Thread Tools Rate Thread

Delete Object Macro

 
 
sg
Guest
Posts: n/a
 
      28th May 2010
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.
 
Reply With Quote
 
 
 
 
Wolfgang Kais
Guest
Posts: n/a
 
      1st Jun 2010
Hello "sg".

"sg" wrote:
> 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*")

--
Regards,
Wolfgang


 
Reply With Quote
 
 
 
 
sg
Guest
Posts: n/a
 
      2nd Jun 2010
Thank you! This was so helpful!

"Wolfgang Kais" wrote:

> Hello "sg".
>
> "sg" wrote:
> > 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*")
>
> --
> Regards,
> Wolfgang
>
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a “Delete Column” Macro to a “Delete Row” Macro cardan Microsoft Excel Programming 7 15th May 2010 06:38 PM
Macro to delete an Object JoeP Microsoft Excel Programming 1 31st Aug 2009 08:24 PM
copy object or export object, can't open object laavista Microsoft Access 5 28th Jun 2009 04:50 AM
Programmatically detach object in unbound object frame to a bound object frame Haiyan Chen Microsoft Access Form Coding 0 4th Mar 2005 03:51 PM
Programmatically detach object in unbound object frame to a bound object frame Haiyan Chen Microsoft Access Form Coding 0 4th Mar 2005 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 AM.