设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[表] 请问怎样判断数据库中的一个表是否存在

[复制链接]
跳转到指定楼层
1#
发表于 2003-4-22 19:23:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问在数据库判断一个表是否存在,怎样判断,如有个表叫test,如果test存在,删除,不存在,就作其他操作
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2003-4-23 00:18:00 | 只看该作者
DoCmd.DeleteObject acTable, "test"
其他操作
3#
 楼主| 发表于 2003-4-23 17:53:00 | 只看该作者
我必须先判断表的存在,再删除

点击这里给我发消息

4#
发表于 2003-4-23 18:14:00 | 只看该作者
One simple way is to recurse through the TableDefs collection of the database. For example, the following function will return true if the specified table exists, False if it doesn't.

'******************** Code Start ************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
'
Function fExistTable(strTableName As String) As Integer
Dim db As Database
Dim i As Integer
    Set db = DBEngine.Workspaces(0).Databases(0)
    fExistTable = False
    db.TableDefs.Refresh
    For i = 0 To db.TableDefs.Count - 1
        If strTableName = db.TableDefs(i).Name Then
            'Table Exists
            fExistTable = True
            Exit For
        End If
    Next i
    Set db = Nothing
End Function
'******************** Code End ************************
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-14 19:43 , Processed in 0.104269 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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