Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003
    Location
    Malaysia
    Posts
    4

    Unanswered: Detect existence of table

    I'm using VBA for Access

    How to detect whether a table is exist or not?

    This is what i want to do actually

    'is table CASS exist?

    If Table CASS Exist then DoCmd.RunSQL ("DROP TABLE CASS")

    How to do that?

  2. #2
    Join Date
    May 2002
    Location
    London
    Posts
    87
    Code:
    Public Function TableExists(strTableName As String) As Boolean
    Dim objTable As AccessObject
    TableExists = False
    For Each objTable In CurrentData.AllTables
        If objTable.Name = strTableName Then
            TableExists = True
        End If
    Next
    End Function
    would do.

    or

    Code:
    Public Function TableExists(strTableName As String) As Boolean
    On Error GoTo Err_TableExists
    TableExists = False
    TableExists = CurrentData.AllTables(strTableName).IsLoaded Or True
    Exit Function
    Err_TableExists:
    Select Case Err.Number
    Case Is = 2467
    'Object not in collection
    Resume Next
    Case Else
    varReturn = MsgBox("Error Number " & Err.Number & vbNewLine & Err.Description)
    Stop
    Resume
    End Select
    End Function

Posting Permissions

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