If Not ObjectExists("table", "tablename") Then
strSQL = "CREATE TABLE t_log ( [key] COUNTER CONSTRAINT ndxkey PRIMARY KEY, [nt_account] TEXT(25), [currentuser] TEXT(30), [datum] DATETIME, [tijd] TIME, [error_msg] MEMO, [AtLocation] TEXT(25))"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End If
Function ObjectExists(strObjectType As String, strObjectName As String) As Boolean
Dim DB As DAO.Database
Dim tbl As TableDef
Dim qry As QueryDef
Dim i As Integer
Set DB = CurrentDb()
ObjectExists = False
If strObjectType = "Table" Then
For Each tbl In DB.TableDefs
If tbl.name = strObjectName Then
ObjectExists = True
GoTo Exit_Handler
End If
Next tbl
ElseIf strObjectType = "Query" Then
For Each qry In DB.QueryDefs
If qry.name = strObjectName Then
ObjectExists = True
GoTo Exit_Handler
End If
Next qry
ElseIf strObjectType = "Form" Or strObjectType = "Report" Or strObjectType = "Module" Then
For i = 0 To DB.Containers(strObjectType & "s").Documents.Count - 1
If DB.Containers(strObjectType & "s").Documents(i).name = strObjectName Then
ObjectExists = True
GoTo Exit_Handler
End If
Next i
ElseIf strObjectType = "Macro" Then
For i = 0 To DB.Containers("Scripts").Documents.Count - 1
If DB.Containers("Scripts").Documents(i).name = strObjectName Then
ObjectExists = True
GoTo Exit_Handler
End If
Next i
Else
MsgBox "Invalid Object Type passed, must be Table, Query, Form, Report, Macro, or Module"
End If
Exit_Handler:
Exit Function
End Function