|
Public Function IsExistTable(strTableName As String) As Boolean
'===============================================================================
'-函数名称: IsExistTable
'-功能描述: 检查表是否存在
'-输入参数说明: 参数1:strTableName As String 检查表的名称
'-返回参数说明: Boolean True表示存在 False 表示不存在
'-使用语法示例: IsExistTable("表1")
'-参考: ADO帮助
'-使用注意:
'-兼容性: 2000,XP,2003
'-作者: fan0217@163.com
'-更新日期: 2006-03-17
'===============================================================================
On Error GoTo Error_IsExistTable
Dim Cnxn As New ADODB.Connection
Dim rstSchema As New ADODB.Recordset
Dim strCnxn As String
Set Cnxn = CurrentProject.Connection
Set rstSchema = Cnxn.OpenSchema(adSchemaTables)
Do Until rstSchema.EOF
If rstSchema!TABLE_NAME = Trim(strTableName) Then
IsExistTable = True
End If
rstSchema.MoveNext
Loop
rstSchema.Close
Cnxn.Close
Set rstSchema = Nothing
Set Cnxn = Nothing
Exit Function
Error_IsExistTable:
IsExistTable = False
If Not rstSchema Is Nothing Then
If rstSchema.State = adStateOpen Then rstSchema.Close
End If
Set rstSchema = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error_IsExistTable"
End If
End Function
|
|