Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    test for table exist (XP)

    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)

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

    Re: test for table exist (XP)

    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))

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: test for table exist (XP)

    Thanks Hans

Posting Permissions

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