有没有办法通过 VBA 确定 Access 表是否包含数据宏?我有数据宏most我的表,但是如果我的代码遇到没有它的表,则会失败。
我没有收到错误消息。相反,代码会继续运行,就像处于无限循环中一样,但我必须强制 Access 退出才能逃脱。
具体来说,我试图保存所有表格和数据宏,以便稍后可以使用(未记录的)LoadFromText 函数重新创建它们。
我在下面的代码示例中用 ** BUG ** 突出显示了该问题。
For Each td In db.TableDefs
If Left(td.Name, 4) <> "MSys" Then
'Save the table as a text file.
DoCmd.TransferText acExportDelim, , td.Name, sExportLocation & "Table_" & td.Name & ".txt", True
'Save the table's data macro as an XML file.
'** BUG **: If a table doesn't have a data macro, Access freezes/starts infinite loop.
Application.SaveAsText acTableDataMacro, td.Name, sExportLocation & "Table_" & td.Name & "_DataMacro.xml"
End If
Next td
我假设我需要某种嵌套的 If 语句,首先检查表中是否存在数据宏。但我不知道该怎么写。
感谢指出 SaveAsText 和 LoadFromText 函数的人们在另一个SO帖子中 https://stackoverflow.com/questions/9206153/how-to-export-access-2010-data-macros。这些功能似乎有很大的潜力。