标题: 用VBA语句怎么判断一个指定的表已经存在! [打印本页] 作者: zhichaochen 时间: 2008-6-19 18:55 标题: 用VBA语句怎么判断一个指定的表已经存在! 用VBA语句怎么判断一个指定的表已经存在!作者: tanhong 时间: 2008-6-19 19:48
'这是本人写的两个检测表是否存在的一个自定义函数,仅供参考
Public Function Btbl (strTblName As String) As Boolean
Dim I As Integer
Dim tdf As TableDef
Btbl=False
'遍历所有表,判断指定表名是否存
For I = 0 To CurrentDb.TableDefs.Count - 1
If CurrentDb.TableDefs(I).Name = strTblName Then
Btbl =True '存在则真
Exit for
End If
Next I
End Function
'代码也可以这样写
Public Function Btbl (strTblName As String) As Boolean
Dim I As Integer
Dim tdf As TableDef
Dim M_Count As Intrger
'判断指定表名是否存
For I = 0 To CurrentDb.TableDefs.Count - 1
If CurrentDb.TableDefs(I).Name = strTblName Then
M_count=M_count+1
End if
Next I
'输入值真则存,假则不存在
If M_count > 0 then
Btbl = True
Else
Btbl = False
End if
End Function
Public Function IsTableExist(tableName As String) As Boolean
Dim i As Integer
Dim result As Boolean
result = False
For i = 0 To Application.CurrentData.AllTables.Count - 1
If Application.CurrentData.AllTables(i).Name = tableName Then
result = True
Exit For
End If
Next
IsTableExist = result
End Function作者: Henry D. Sy 时间: 2008-6-20 01:29
Public Function IsTableExist(strTableName As String) As Boolean