Question: 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 06.06.2010 will be logged in 2010\_06\_06 named table. When date is changed I'll create a table named 2010\_06\_07. But the problem is if this table is already created.

Any suggestions how to check if table exists in Access?

Answer: 
Here's another solution, will be a bit faster than looping over all of the tables.

```
Public Function doesTableExist(strTableName As String) As Boolean
    Dim db As DAO.Database
    Dim td As DAO.TableDef
    Set db = CurrentDb
    On Error Resume Next
    Set td = db.TableDefs(strTableName)
    doesTableExist = (Err.Number = 0)
    Err.Clear
End Function

```
This question is quite old but I found that no answer is satisfying, because:

* they do not handle the case of "bad" linked tables, where the linked table points to a non existing db or table.
* since linked tables are potentially huge, we must be able to check them with a fast query.

So here is my simple but more complete solution:

```vb
    Function isTableOk(tblName As String) As Boolean
    'works with local or linked tables
        Dim db As DAO.Database, rs As DAO.Recordset
        Dim sSql As String
        sSql = "SELECT TOP 1 ""xxx"" AS Expr1 FROM [" & tblName & "]"

        On Error Resume Next
        Err.Clear
        Set db = CurrentDb
        Set rs = db.OpenRecordset(sSql)
        isTableOk = (Err.Number = 0)
        rs.Close
    End Function

```

You can even check table in an *external* Access db with this version:

```vb
    Function isTableOk(tblName As String, Optional dbName As String) As Boolean
    'works with local or linked tables, or even tables in external db (if dbName is provided)

        Dim db As DAO.Database, rs As DAO.Recordset
        Dim sSql As String

        Set db = CurrentDb
        sSql = "SELECT TOP 1 'xxx' AS Expr1 FROM [" & tblName & "]"
        If Len(dbName) > 0 Then 'external db 
            sSql = sSql & " IN '" & dbName & "'"
        End If
        Err.Clear
        On Error Resume Next
        Set rs = db.OpenRecordset(sSql)
        isTableOk = (Err.Number = 0)
        rs.Close
    End Function

```