MS Acess 2000 - Delete Object (acTable) and Table does not exist

Posted on 2007-10-01
Last Modified: 2012-06-21
If the table does not exists I get an error on the delete object - can I check if it exists and if it does then do the delete object?

'Delete Import Table before Linking New SAM Data
DoCmd.DeleteObject acTable, "tbl_Sam_Import_Data"

'The File is linked rather than imported
DoCmd.TransferText acLinkDelim, "SAM Data Import Specification", "tbl_Sam_Import_Data", strImportFileName, False
Question by:Marilync1266
    LVL 14

    Accepted Solution

    You can scan the list of tabledefs (currentdb.tabledefs) for one with the appropriate name

    dim tb as tabledef
    dim wFound as boolean
    wFound = false
    for each tb in currentdb.tabledefs
       if = "tbl_Sam_Import_Data" then
          wFound = true
          exit for
       end if
    if wFound then
       docmd.deleteobject actable, "tbl_Sam_Import_Data"
    end if
    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    Here is the Quick-n-Dirty way:
    (if you are only concerned about one table)

    Sub DeleteTable()
    On Error Resume Next
        DoCmd.DeleteObject acTable, "tbl_Sam_Import_Data"
    End sub

    Basically; If you get an error, it moves on (to the end of the sub, in this case).
    If you don't get an error, it deletes the table.

    However, you will have to change it to catch the specific error (7874), if you install a more robust error handler.

    HTH as well

    Jeff Coachman
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now