Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    15

    Unanswered: Mass Delete Tables in VBA

    Can anyone help me mass delete tables in my Access database? I'd like to delete all tables of which the names contain a certain string but I don't know where to begin...

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Search through your Access VBA help files for the tabledefs collection.
    It tells you how to scroll through each table in your database, and since
    "name" is part of that collection, you can compare that to your search string...
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2005
    Posts
    31
    Air Code:

    Code:
    Public Sub DeleteTables()
    
      Dim db As DAO.Database
      Dim tds As DAO.TableDefs
      Dim td As DAO.TableDef
    
      Set db = CurrentDb()
      Set tds = db.TableDefs
    
      For Each td In tds
        If td.Name = Left("Your Pattern", 1) Then
          tds.Delete (td.Name)
        Else
          '<your code>
        End If
      Next
    
      Set td = Nothing
      db.Close
      Set db = Nothing
    
    End Sub
    Obviously untested, please investigate further.

  4. #4
    Join Date
    Jan 2005
    Posts
    15
    Thank you both! I am able to wipe out the tables with the common thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •