Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    123

    Unanswered: Checking if a TableDef exists

    I have a routine that creates a temporary table, and at the end deletes it. However, I would like to check at the beginning of the routine if the table is still there just in case it didn't get deleted the last time. How do I do this?

  2. #2
    Join Date
    Sep 2004
    Posts
    161
    Unfortunately there is not function for that in Access97 (may be in A2k).
    You can is to read the TableDefs collection of the Database object to check the
    name of your table, or to test a property like recordcount and
    intercept the error if the table does not exist.

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    You can check for the existance of a table using the Error Handel routine

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Example
    Add the next function to one of your modules

    PHP Code:
    Function TableExist(TableName As String) As Boolean
    Dim Db 
    As Database
    Dim tbl 
    As Recordset

    On Error 
    GoTo TableExistError

        Set Db 
    CurrentDb
        Set tbl 
    Db.OpenRecordset(TableName)
        
    TableExist True
        Set tbl 
    Nothing
        
        
    GoTo tableEnde

    TableExistError
    :
        
    TableExist False
        Set tbl 
    Nothing
        
    GoTo tableEnde
    tableEnde
    :
    End Function 
    To call it
    If TableExist("yourTempTableName") then
    DoCmd.RunSQL "Drop Table " & yourTempTableName
    EndIf

Posting Permissions

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