Function TableExists(TableName As String) As Boolean
Dim tdf As TableDef
On Error GoTo ErrHandler
Set tdf = CurrentDb.TableDefs(TableName)
TableExists = True
Finish:
Set tdf = Nothing
Exit Function
ErrHandler:
TableExists=False
Resume Finish
End Function
Or you can use a recordset based on MSysObjects table:
Function TableExists(TableName As String) As Boolean
Dim rst As DAO.Recordset
Dim strSQL As String
On Error GoTo ErrHandler
Set rst = CurrentDb.OpenRecordset(strSQL)
If rst.RecordCount > 0 Then
TableExists = True
Else
TableExists = False
End If
rst.Close
Finish:
Set rst = Nothing
Exit Function
ErrHandler:
'you shouldn't get here, but...
MsgBox Err.Number & Err.Description
Resume Finish
End Function
The code is written in DAO model, for ADO you'll have to modify it a little bit.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.