我使用 MS Access 宏和查询来构建我的应用程序。我使用一些临时导入文件,需要运行宏或一些 VBA 来测试它们是否存在,如果存在,则删除它们。
我的表名是“TempImport1”
我已经通过谷歌搜索对此进行了研究,并且有一些可能有用的 VBA。我过去在一个按钮下剪切/粘贴了 VBA 代码,它可以工作,但这次不行。如何将代码放入模块或单击子按钮?
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 TrapError
Dim x
x = DCount("*", sTblName)
IsTable = True
Exit Function
TrapError:
Debug.Print Now, sTblName, Err.Number, Err.Description
IsTable = False
End Function
最佳答案
删除临时导入1 表如果存在,只需使用以下函数。
Function DeleteTables()
If Not IsNull(DLookup("Name", "MSysObjects", "Name='TempImport1' AND Type = 1")) Then
DoCmd.DeleteObject acTable, "TempImport1"
End If
End Function
创建函数后,创建宏,添加操作运行代码,然后输入
DeleteTables()
在函数名称中。然后,您可以运行一个宏来删除该表(如果存在)。
关于vba - 如果表存在,如何删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43833709/