是否可以以编程方式枚举 Access 2010+ 数据库中的数据宏?如果是这样,怎么做?
注意:数据宏是在表设计器 UI 的上下文中创建的类似触发器的过程。它们是 Acces 2010 中的新功能。它们与易于枚举的普通宏不同。
它们有自己的新AcObjectType
枚举值 : acTableDataMacro
,但我找不到引用它们的 Access 或 DAO 对象模型的其他方面。它们甚至没有出现在MSysObjects
表格中。
此代码会将 DataMacro 元数据导出到 XML 文档(Source):
Sub DocumentDataMacros()
'loop through all tables with data macros
'write data macros to external files
'open folder with files when done
' click HERE
' press F5 to Run!
' Crystal
' April 2010
On Error GoTo Proc_Err
' declare variables
Dim db As DAO.Database _
, r As DAO.Recordset
Dim sPath As String _
, sPathFile As String _
, s As String
' assign variables
Set db = CurrentDb
sPath = CurrentProject.Path & "\"
s = "SELECT [Name] FROM MSysObjects WHERE Not IsNull(LvExtra) and Type =1"
Set r = db.OpenRecordset(s, dbOpenSnapshot)
' loop through all records until the end
Do While Not r.EOF
sPathFile = sPath & r!Name & "_DataMacros.xml"
'Big thanks to Wayne Phillips for figuring out how to do this!
SaveAsText acTableDataMacro, r!Name, sPathFile
'have not tested SaveAsAXL -- please share information if you do
r.MoveNext
Loop
' give user a message
MsgBox "Done documenting data macros for " & r.RecordCount & " tables ", , "Done"
Application.FollowHyperlink CurrentProject.Path
Proc_Exit:
' close and release object variables
If Not r Is Nothing Then
r.Close
Set r = Nothing
End If
Set db = Nothing
Exit Sub
Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " DocumentDataMacros"
Resume Proc_Exit
Resume
End Sub
编辑:戈德指出您希望 DataMacros 反对标准宏。我在这里找到了一些代码并对其进行了测试(它有效)
当您点击该链接时,我测试了 top 函数,它为 XML 文档中的每个表保存了有关表宏的信息。它工作得很好,对写它的人的支持。