Office中国论坛/Access中国论坛

标题: 请问怎样判断数据库中的一个表是否存在 [打印本页]

作者: gyq    时间: 2003-4-22 19:23
标题: 请问怎样判断数据库中的一个表是否存在
请问在数据库判断一个表是否存在,怎样判断,如有个表叫test,如果test存在,删除,不存在,就作其他操作
作者: 李啸林    时间: 2003-4-23 00:18
DoCmd.DeleteObject acTable, "test"
其他操作

作者: gyq    时间: 2003-4-23 17:53
我必须先判断表的存在,再删除
作者: zhuyiwen    时间: 2003-4-23 18:14
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 ************************




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3