Check if access table exists

前端 未结 5 2066
萌比男神i
萌比男神i 2020-11-30 09:50

I want to log web site visits\' IP, datetime, client and refferer data to access database but I\'m planning to log every days log data in separate tables in example logs for

5条回答
  •  星月不相逢
    2020-11-30 10:27

    I have found querying system tables or tabledefs to be unreliable and introduce unpredictable behaviour in scripts where tables get regularly created and dropped.

    Based on my results, my hypothesis is that these tables aren't necessarily updated at the exact instant a CREATE or DROP is executed, or that concurrency issues are preventing me from getting an accurate result.

    I've found the following method to be more reliable:

    Public Function TableExists(theDatabase As Access.Application, _
        tableName As String) As Boolean
    
        ' Presume that table does not exist.
        TableExists = False
    
        ' Define iterator to query the object model.
        Dim iTable As Integer
    
        ' Loop through object catalogue and compare with search term.
        For iTable = 0 To theDatabase.CurrentData.AllTables.Count - 1
            If theDatabase.CurrentData.AllTables(iTable).Name = tableName Then
                TableExists = True
                Exit Function
            End If
        Next iTable
    
    End Function
    

    There should be no runtime issue iterating unless there is an staggeringly enormous collection of tables.

提交回复
热议问题