• test for table exist (XP)

    Author
    Topic
    #435044

    what is the best way to see if a table exists in a backend database?
    I’m using
    Public Function DoesTableExist(strTable As String, Optional strDatabase As String) As Boolean
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
    If strDatabase = “” Then
    Set dbs = CurrentDb
    Else
    Set dbs = OpenDatabase(strDatabase)
    End If

    Set tdf = dbs.TableDefs(strTable)
    DoesTableExist = Not (tdf Is Nothing)

    Viewing 0 reply threads
    Author
    Replies
    • #1027197

      Your code should work, but you’ll have to insert a line

      On Error Resume Next

      above the line

      Set tdf = …

      You could also use

      On Error Resume Next
      DoesTableExists = IsObject(dbs.TableDefs(strTable))

    Viewing 0 reply threads
    Reply To: test for table exist (XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: