你可以先新建个模块,放入以下函数
'=========================================================================================
'函数名称: ObjectIsExists
'功能描述: 检查数据库中某个对象是否存在,可以是窗体,表、查询,报表、宏等
'输入参数: strObjectType 必选的。strObjectType 参数是一个 AcObjectType 对象类型常量,
' 用于指定要检查的数据库对象的类型acForm,acQuery,acReport,acTable,acMacro,acModule
' strObjectName 必选的。strObjectName 参数是要检查的数据库对象的名称
'返回参数: True/False
'使用示例: ObjectIsExists(acForm,"窗体名称")
'作 者: 金宇
'创建日期: 2012-1-10
'=========================================================================================
Function ObjectIsExists(ByVal strObjectType As AcObjectType, ByVal strObjectName As String) As Boolean
On Error GoTo ErrorHandler
Dim strResult As String
Select Case strObjectType
Case acTable
strResult = CurrentDb.TableDefs(strObjectName).Name
Case acQuery
strResult = CurrentDb.QueryDefs(strObjectName).Name
Case acForm
strResult = CurrentProject.AllForms(strObjectName).Name
Case acReport
strResult = CurrentProject.AllReports(strObjectName).Name
Case acMacro
strResult = CurrentProject.AllMacros(strObjectName).Name
Case acModule
strResult = CurrentProject.AllModules(strObjectName).Name
End Select
ObjectIsExists = True
Exithere:
Exit Function
ErrorHandler:
Resume Exithere
End Function
然后在需要判断的地方加代码
if ObjectIsExists(acTable, "需要检测的表名称") then
msgbox "存在此表!"
else
msgbox "不存在此表"
end if