Kar*_*hik 16 ms-access vba access-vba
可能重复:
检查访问表是否存在
我是vba宏的新手.知道如何检查表是否存在?我搜索过以前的帖子,但没有得到明确的解决方案.
Kar*_*hik 32
设置对Microsoft Access 12.0对象库的引用允许我们使用DCount测试表是否存在.
Public Function ifTableExists(tblName As String) As Boolean
If DCount("[Name]", "MSysObjects", "[Name] = '" & tblName & "'") = 1 Then
ifTableExists = True
End If
End Function
Run Code Online (Sandbox Code Playgroud)
Tob*_*ouw 11
Exists = IsObject(CurrentDb.TableDefs(tablename))
Run Code Online (Sandbox Code Playgroud)
Pat*_*rez 10
我知道问题已经得到解答,但我发现现有的答案无效:
对于具有非工作后端的链接表,它们将返回True.
使用DCount可能会慢得多,但更可靠.
Function IsTable(sTblName As String) As Boolean
'does table exists and work ?
'note: finding the name in the TableDefs collection is not enough,
' since the backend might be invalid or missing
On Error GoTo hell
Dim x
x = DCount("*", sTblName)
IsTable = True
Exit Function
hell:
Debug.Print Now, sTblName, Err.Number, Err.Description
IsTable = False
End Function
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
117107 次 |
最近记录: |