Deleting a list of tables from a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytes access nubie
    New Member
    • Oct 2008
    • 34

    Deleting a list of tables from a database

    There is a table that lists all of the linked DBF tables in the current database in the field "ForeignNam e". I need to create code that will delete all these tables whose names are in the "ForeignNam e" field (the table is created from a make table query the filters on *DBF names in this field).

    This code will be distributed to a about 50 employees in our dept. We are trying to automate this process so that employees do not have to manually delete 15 or 20 linked tables in their databases.

    Any help is appreciated.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. Create a Recordset based on the Table containing the Names of the Tables to be Deleted.
    2. Loop through this Recordset, and for each Record, Delete the Table with the corresponding [ForeignName].
    3. The Pseudo Code would look something like this:
      Code:
      On Error Resume Next
      
      'Recordset rs previously created
      With rs
        Do While Not .EOF
          CurrentDB.Tabledefs.Delete ![ForeignName]
            .MoveNext
        Loop
      End With

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      If the only requirement is to delete all linked tables then a separate table to store them in is unnecessary. The TableDefs() collection contains each TableDef in the database, and each has a Connection property from which it is easy to determine whether or not it is linked, and how.

      Comment

      Working...