Delete Object Macro

Discussion in 'Access Macros' started by sg, May 28, 2010.

  1. sg

    sg Guest

    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.
     
    sg, May 28, 2010
    #1
    1. Advertisements

  2. 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*")
     
    Wolfgang Kais, Jun 1, 2010
    #2
    1. Advertisements

  3. sg

    sg Guest

    Thank you! This was so helpful!

     
    sg, Jun 2, 2010
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.