Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Delete Multiple Tables Quickly


View products that this article applies to.

This article was previously published under Q210307
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


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.

↑ Back to the top


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.

  1. Create a module and type the following line in the Declarations section if it is not already there:
    Option Explicit
    
  2. 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
    
  3. 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.

↑ Back to the top


References

For more information about Tabledefs, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type TableDefs Collection in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB210307, kbusage, kbhowto

↑ Back to the top

Article Info
Article ID : 210307
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 390