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

    Runtime error 3221 (Access 2000)

    How can i delete all the tables available in a database but not the system tables ?

    I have the following function

    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
    DoCmd.DeleteObject acTable, tdf.Name
    Next
    End Function

    However i receive Runtime error 321 saying "The database engine could not lock table MSysAccessObjects since it is used by another
    person or process"

    I will be grateful for any advice

  2. #2
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Runtime error 3221 (Access 2000)

    Add an If statement, inside the For-Next loop that tests if it's a system table or not...

    If Left(tdf.Name, 4) <> "MSys" Then
    DoCmd.DeleteObject acTable, tdf.Name
    End If

    HTH

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Runtime error 3221 (Access 2000)

    Here's another method that doesn't depend on the name of the table but looks at its systemobject attribute:

    For Each tdf In db.TableDefs
    If Not (tdf.Attributes And dbSystemObject) Then
    db.tabledefs.Delete tdf.name
    End If
    Next tdf
    Charlotte

Posting Permissions

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