Deleting a list of tables from a database

Access nubie

Registered User.
Local time
Today, 02:28
Joined
Oct 24, 2008
Messages
14
In access 2013, I have a table that lists all of the linked DBF tables in the current database in the field "ForeignName". I need to create code that will delete all these tables whose names are in the "ForeignName" field (the table is created from a make table query the filters on *DBF names in this field).
Additionally, these same tables that now reside as .CSV files in D:\Data will have to all be setup as linked tables in the current database.

This code will be distributed to 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 & then link them all manually.

Any help is appreciated.
 
Are the tables named in such a way that they can be identified as a group? In other words, do they all begin or end with a certain text value, such as "tblDBF"? If so, you could delete them based on that, rather than maintaining a table of table names. The following code would do it:

Code:
Private Sub cbDeleteTables_Click
    Dim db As Database
    Dim tbl As TableDef

    Set db = CurrentDb()
    For Each tbl In db.TableDefs
        If Left(tbl.Name, 6) = "tblDBF" Then
            DoCmd.DeleteObject ObjectType:=acTable, Objectname:= tbl.Name
        End If
    Next
    Set tbl = Nothing
    Set db = Nothing
End Sub

Otherwise, you could set up a loop to read through the table names table and use DoCmd.DeleteObject to delete them.
 

Users who are viewing this thread

Back
Top Bottom