设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[表] 用VBA语句怎么判断一个指定的表已经存在!

[复制链接]
1#
发表于 2008-6-19 19:48:18 | 显示全部楼层
'这是本人写的两个检测表是否存在的一个自定义函数,仅供参考
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

[ 本帖最后由 tanhong 于 2008-6-21 09:34 编辑 ]
2#
发表于 2008-6-20 15:54:01 | 显示全部楼层
捕获错误的方法也不错!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-30 07:34 , Processed in 0.114118 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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