Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check existance of a table (2000/2002)

    How can I check the existance of a table in code? I have code connected to a button that links a user to a table in an external database, then names the linked table "tblStudents". If a table named tblStudents already exists, the linked table is named tblStudents1 and does not replace the existing table. I can have my code delete the existing table but I only want to do that if there is a table by that name already.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

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

    Re: Check existance of a table (2000/2002)

    The simplest way is to trap the error that occurs if you try to delete a non-existing table:

    Sub DeleteATable()
    On Error GoTo ErrHandler
    DoCmd.DeleteObject acTable, "Table1"
    ' code to link table goes here
    Exit Sub

    ErrHandler:
    Select Case Err
    Case 7874 ' Table not found - continue
    Resume Next
    Case Else
    MsgBox Err.Description, vbExclamation
    End Select
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check existance of a table (2000/2002)

    Thank you. That worked like a charm. I can also see where the Select Case statement in the ErrHandler would help in some other databases I support.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

Posting Permissions

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