Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete all objects (Access 2000)

    I want to delete all objects from a database, e.g. tables,forms,etc, without enumerating them.Does anubody know how to do it? I want to do it by code and not manually

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete all objects (Access 2000)

    Here a function to delete all tables, queries, forms and reports. Don't forget to set a reference to Microsoft DAO 3.6 Object Library in Tools, References.
    <pre>Function DeleteAll()
    Dim db As dao.Database
    Dim tdf As dao.TableDef
    Dim qdf As dao.QueryDef
    Dim frm As Document
    Dim rpt As Document
    Set db = CurrentDb
    'Tables
    For Each tdf In db.TableDefs
    If Left(tdf.Name, 4) <> "MSys" Then
    DoCmd.DeleteObject acTable, tdf.Name
    End If
    Next
    'queries
    For Each qdf In db.QueryDefs
    DoCmd.DeleteObject acQuery, qdf.Name
    Next
    'Forms
    For Each frm In db.Containers("Forms").Documents
    DoCmd.DeleteObject acForm, frm.Name
    Next
    'reports
    For Each rpt In db.Containers("Reports").Documents
    DoCmd.DeleteObject acReport, rpt.Name
    Next
    End Function</pre>

    Francois

Posting Permissions

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