Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Melbourne, Victoria, Australia
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete a table (Access 2000 SR-1)

    How do I delete a table using code, or for that matter a query?
    Thanks in advance

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete a table (Access 2000 SR-1)

    There are several methods:

    1. The DoCmd.DeleteObject method.

    DoCmd.DeleteObject acTable, "tblToBeDeleted"
    DoCmd.DeleteObject acQuery, "qrySoonGone"

    2. The DAO TableDefs and QueryDefs collections (you need to have a reference to the Microsoft DAO 3.6 Object Library).

    CurrentDb.TableDefs.Delete "tblToBeDeleted"
    CurrentDb.QueryDefs.Delete "qrySoonGone"

    3. SQL (for tables only)

    DoCmd.RunSQL "DROP TABLE tblToBeDeleted"

  3. #3
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Melbourne, Victoria, Australia
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete a table (Access 2000 SR-1)

    Thanks Hans,
    As far as deleting a table, which is the cleaner or preferred way?
    Are there any significant consequences of one way over the other?
    Regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete a table (Access 2000 SR-1)

    SQL is usually fastest, but I don't think that there will be a significant difference between the methods.

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Delete a table (Access 2000 SR-1)

    In a query you can delete all data in a table using the following sql,

    Delete * from Tablename;

    however, I dont think you can delete a table with a query as the query completes an action against the table.

    If not using code as shown in Hans' post, you could drop the table using a Macro, but the code is just as easy.
    Regards,

    Gary
    (It's been a while!)

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

    Re: Delete a table (Access 2000 SR-1)

    DDL and DML queries act on the table itself, not on the records in it.
    Charlotte

  7. #7
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Delete a table (Access 2000 SR-1)

    Thanks Charlotte. I will look up additional information on these types of queries.
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

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