MS Access 对象(表格、报告)显示创建或修改日期
Posted
技术标签:
【中文标题】MS Access 对象(表格、报告)显示创建或修改日期【英文标题】:MS Access objects (forms, reports) display created or modified date 【发布时间】:2016-05-17 04:20:46 【问题描述】:参考这个问题: MS Access 2013 对象(表、查询)显示创建或修改日期 马特用这个代码回答:https://***.com/a/36712839/6342925
第一次奏效。 如何添加到代码中以同时列出表单、报告和宏 - 并显示创建和修改日期?
【问题讨论】:
【参考方案1】:使用CurrentProject.All*
集合:AllForms
; AllReports
;和AllMacros
。
这是立即窗口中的一个示例:
for each obj in CurrentProject.AllForms : ? obj.Name, obj.DateCreated, obj.DateModified : next
frmClaims 8/11/2015 12:11:46 PM 10/6/2015 1:08:28 PM
frmInvoices 3/8/2015 5:04:24 PM 10/6/2015 1:08:28 PM
frmChoosePerson 3/28/2015 1:11:51 PM 2/28/2016 8:29:28 PM
for each obj in CurrentProject.AllReports : ? obj.Name, obj.DateCreated, obj.DateModified : next
rptPassThruQuery 3/9/2016 1:04:38 PM 3/9/2016 2:23:38 PM
rptChangeSort 7/27/2015 10:45:38 AM 10/6/2015 1:08:30 PM
for each obj in CurrentProject.AllMacros : ? obj.Name, obj.DateCreated, obj.DateModified : next
Macro2 6/17/2015 10:21:58 AM 6/17/2015 10:21:58 AM
【讨论】:
谢谢汉斯,我让它工作了。作为 VBA 的新手,我不了解 Access 如何处理表和查询与表单和报告之间的理论或区别。唉,你的代码帮了大忙! 是的,没有一个“路线”可以获取所有不同的数据库对象类型。这可能会令人困惑和沮丧。一旦您了解了每种类型的合适路线……您就有了一个良好的开端。 :-) 我在下面添加了整个 VBA 代码 - 记住如何再次执行此操作!【参考方案2】:Public Function CreatedModified()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim strSql As String
Dim obj As AccessObject
strSql = "DELETE * FROM tblCCSObjects"
Set db = CurrentDb
db.Execute strSql, dbFailOnError
Set rs = db.OpenRecordset("tblCCSObjects")
With rs
' tables
For Each tdf In db.TableDefs
If Not (tdf.Name Like "*MSys*" Or tdf.Name Like "~*") Then
.AddNew
!ObjectType_Order = "1"
!ObjectType = "Table"
!ObjectName = tdf.Name
!DateCreated = tdf.DateCreated
!DateModified = tdf.LastUpdated
.Update
End If
Next
' queries
For Each qdf In db.QueryDefs
If Not (qdf.Name Like "*MSys*" Or qdf.Name Like "~*") Then
.AddNew
!ObjectType_Order = "2"
!ObjectType = "Query"
!ObjectName = qdf.Name
!DateCreated = qdf.DateCreated
!DateModified = qdf.LastUpdated
.Update
End If
Next
' forms
For Each obj In CurrentProject.AllForms
.AddNew
!ObjectType_Order = "3"
!ObjectType = "Forms"
!ObjectName = obj.Name
!DateCreated = obj.DateCreated
!DateModified = obj.DateModified
.Update
Next
' reports
For Each obj In CurrentProject.AllReports
.AddNew
!ObjectType_Order = "4"
!ObjectType = "Reports"
!ObjectName = obj.Name
!DateCreated = obj.DateCreated
!DateModified = obj.DateModified
.Update
Next
' macros
For Each obj In CurrentProject.AllMacros
.AddNew
!ObjectType_Order = "5"
!ObjectType = "Macros"
!ObjectName = obj.Name
!DateCreated = obj.DateCreated
!DateModified = obj.DateModified
.Update
Next
End With
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
【讨论】:
汉斯,再次感谢您的指导。正如您所建议的,我确实修改了代码,去掉了表单、报告和宏的 If..then 语句。一切仍然有效!同时,我更改了表的名称,并添加了“对象类型排序顺序”字段,因此我可以对非字母数字进行排序。以上是清理后的代码。 迪斯科。再次感谢您的帮助。我想 Dim obj As AccessObject 和 dbFailOnError 是正常的协议类型的东西。我的意思是在上面补充一点,我必须从一个子例程更改为一个函数,以允许“RunCode”在宏中工作。以上是关于MS Access 对象(表格、报告)显示创建或修改日期的主要内容,如果未能解决你的问题,请参考以下文章