Microsoft KB Archive/210307

= ACC2000: How to Delete Multiple Tables Quickly =

Article ID: 210307

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210307



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
In some situations, you may want to delete multiple tables quickly, rather than delete them one at a time. For example, when you import data from another product, an error table may be created. After many imports, there may be several error tables to delete. This article shows you how to use Data Access Objects (DAO) to delete these multiple tables.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
The following example demonstrates how to use DAO in code to loop through the TableDefs collection and delete any tables whose name begins with "Import Errors."

NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

  Create a module and type the following line in the Declarations section if it is not already there: Option Explicit   Type the following procedure: Function DeleteImportErrorTables Dim db As DAO.Database, t As DAO.TableDef, i As Integer Set db = CurrentDB For i = db.tabledefs.count - 1 To 0 Step -1 Set t = db.tabledefs(i) If t.name Like "Import Errors*" Then db.tabledefs.Delete t.name End If     Next i   db.Close End Function   To test this function, type the following line in the Immediate window, and then press ENTER: ? DeleteImportErrorTables

Any table whose name begins with "Import Errors" is deleted without confirmation. 

