表名是否在数据库中存在的问题,MSDN有错??-----很着急,请大家帮忙,在线等待

lhxm007 2002-09-01 02:13:20
我的程序要检验一下在数据库中某个表是否存在
刚好在MSDN中有这么一段程序,我就直接试了试
Const NameNotInCollection = 3265
Public DB As Database

Private Function ExistsTableQuery(TName As String) As Boolean
Dim Test As String
On Error Resume Next

' See if the name is in the Tables collection:
Test = DB.TableDefs(TName).Name
If Err <> NameNotInCollection Then
ExistsTableQuery = True
' Reset the error variable:
Err = 0
' See if the name is in the Queries collection:
Test = DB.QueryDefs(TName$).Name
If Err <> NameNotInCollection Then
ExistsTableQuery = True
End If
End If
End Function


Private Sub Form_Load()
Set DB = DBEngine.Workspaces(0).OpenDatabase_("d:\company_admin\company_admin.mdb.mdb")
Debug.Print "BadTable "; IIf(ExistsTableQuery("sell"), _
"does", "doesn't"); " exist."
Debug.Print "Authors "; IIf(ExistsTableQuery("Authors"), _
"does", "doesn't"); " exist."
End Sub
里面的语句我基本上没改,只修改了OpenDatabase中的路径,编译时也没有报错,可是运行的时候窗口上什么也没有,这是怎么回事??难道MSDN有错吗??
...全文
27 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lhxm007 2002-09-01
  • 打赏
  • 举报
回复
谢谢微风轻扬,这么好改哦,我就没想改过
唉,都是太迷信微软那些坏家伙了,:)
Azi03 2002-09-01
  • 打赏
  • 举报
回复
Debug.Print "BadTable "; IIf(ExistsTableQuery("sell"), _
"does", "doesn't"); " exist."
Debug.Print "Authors "; IIf(ExistsTableQuery("Authors"), _
"does", "doesn't"); " exist."
你把它改成这样试试::

if ExistsTableQuery("sell")=true then
msgbox "does exist sell"
else
msgbox "doesn.t exist sell"
endif
if ExistsTableQuery("Authors")=true then
msgbox "does exist Authors"
else
msgbox "doesn.t exist Authors"
endif

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧