Hi Eric,
Thanks for getting me pointed in the right direction.
One thing I need to do though is test for the object type, as the name may
not be unique. Can you tell me if you think the code below will work? It
appears that it should, if the values assisgned to "intObjectType" are
constants that do not change.
==========================
'Function ObjectExists accepts (3) parameters; an ObjectName, an ObjectType,
and an optional DatabaseName
Function ObjectExists(strObjectName As String, strObjectType As String,
Optional strDb As String) As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim intObjectType As Integer
'Set the database location
If strDb = "" Then
Set db = CurrentDb
Else
Set db = OpenDatabase(strDb)
End If
'Set the object type as integer
Select Case strObjectType
Case "acTable"
intObjectType = "In(1,6)"
Case "acQuery"
intObjectType = "= 5"
Case "acForm"
intObjectType = "= -32768"
Case "acReport"
intObjectType = "= -32764"
Case "acMacro"
intObjectType = "= -32766"
Case "acModule"
intObjectType = "= -32761"
End Select
'Set the SELECT statement
strSQL = "SELECT MSysObjects.Name FROM MSysObjects "
strSQL = strSQL & "WHERE Name = '" & strObjectName & "' AND Type " &
intObjectType & ";"
Debug.Print strSQL
Set rs = db.OpenRecordset(strSQL)
'Set the return value of ObjectExists, based on whether or not a record
is returned
intCount = rs.RecordCount
ObjectExists = IIf(intCount = 0, False, True)
Set rs = Nothing
Set db = Nothing
End Function
=================