Check if table exists?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan2kx
    Contributor
    • Oct 2007
    • 365

    #1

    Check if table exists?

    Is there a line of code i could use to check if a table exists (so that i can delete it if it does)

    im thinking

    If table1 = true then
    etc

    thanks

    Dan
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    This link should get you started:

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Here is the General logic:
      Code:
      Dim tdf As DAO.TableDef
      Dim blnTableExists As Boolean
      Dim strTableName As String
      
      blnTableExists = False      'Initialize to False
      strTableName = "<Your Table Name Here>"
      
      For Each tdf In CurrentDb.TableDefs
        If tdf.Name = strTableName Then
          blnTableExists = True
            Exit For
        End If
      Next
      
      If blnTableExists Then
        MsgBox "The [" & strTableName & "] Table exists in Current Database"
      Else
        MsgBox "The [" & strTableName & "] Table does not exist in Current Database"
      End If

      Comment

      Working...