设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2122|回复: 5
打印 上一主题 下一主题

[与其它组件] 如何判断一个表是否存在?

[复制链接]
1#
发表于 2006-8-3 02:15:00 | 显示全部楼层
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-3 06:37 , Processed in 0.071208 second(s), 23 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表