[英]How to compare MS-Access created and last modified dates of tables, queries, forms, etc.?
I like to create a list when tables, queries, forms etc. were created and updated in an Access 2010 database.我喜欢在 Access 2010 数据库中创建和更新表、查询、表单等时创建一个列表。
In theory this is possible with a little VBA code but unfortunately this code shows the wrong information.从理论上讲,这可以通过一些 VBA 代码实现,但不幸的是,这段代码显示了错误的信息。 I tested it myself and it is confirmed by Microsoft here: https://support.microsoft.com/en-us/kb/299554
我自己测试过,微软在这里确认: https : //support.microsoft.com/en-us/kb/299554
Access shows the correct modified date on the Navigation Panel but it seems to be impossible to access this information via VBA or in any table. Access 在导航面板上显示正确的修改日期,但似乎无法通过 VBA 或任何表格访问此信息。 Some time ago I searched for this on the internet and a couple of people confirmed the problem but nobody had an answer.
前段时间我在互联网上搜索了这个,几个人确认了这个问题,但没有人有答案。
Now my question: Does anybody know how to export the correct modified date information from Access (shown in the Navigation Panel)?现在我的问题是:有人知道如何从 Access 导出正确的修改日期信息(显示在导航面板中)?
If this is impossible (my current research suggest this) does anyone know a reliable way to compare one database file to another and show all the differences in tables, queries, forms, etc.?如果这是不可能的(我目前的研究表明这一点),是否有人知道将一个数据库文件与另一个数据库文件进行比较并显示表、查询、表单等中所有差异的可靠方法?
This is all about the design of the Access objects and not about any data stored in the tables.这完全是关于 Access 对象的设计,而不是关于存储在表中的任何数据。
That linked article describes why the LastUpdated
property doesn't give you what you want for database objects such as forms and reports.该链接文章描述了为什么
LastUpdated
属性没有为您提供所需的数据库对象(如窗体和报表)。 Unfortunately it doesn't tell you that you can use DateModified
from the appropriate CurrentProject
collection for those.不幸的是,它并没有告诉您可以从相应的
CurrentProject
集合中使用DateModified
。
For example, consider this screen capture of a form in the Navigation pane:例如,请考虑导航窗格中表单的以下屏幕截图:
When referencing that form in the Documents collection, LastUpdated
and DateCreated
both return the same value:在 Documents 集合中引用该表单时,
LastUpdated
和DateCreated
都返回相同的值:
? CurrentDb.Containers("Forms").Documents("Form1").DateCreated
8/20/2012 10:51:07 PM
? CurrentDb.Containers("Forms").Documents("Form1").LastUpdated
8/20/2012 10:51:07 PM
However DateModified
for that same form in the CurrentProject.AllForms
collection gives you the value which is displayed in the Navigation pane:但是,
CurrentProject.AllForms
集合中同一表单的DateModified
为您提供了显示在导航窗格中的值:
? CurrentProject.AllForms("Form1").DateModified
7/1/2015 6:47:40 AM
Note you can also get DateCreated
via AllForms
:请注意,您还可以通过
AllForms
获取DateCreated
:
? CurrentProject.AllForms("Form1").DateCreated
8/20/2012 10:51:07 PM
Other CurrentProject
collections include: AllMacros
;其他
CurrentProject
集合包括: AllMacros
; AllModules
; AllModules
; and AllReports
.和
AllReports
。 Beware that modules are saved together so DateModified
shows you the time the project was last saved.请注意,模块保存在一起,因此
DateModified
显示上次保存项目的时间。 That means each module will show that same time, the same as displayed in the Navigation pane.这意味着每个模块将同时显示,与导航窗格中显示的时间相同。
Here is a function that will retrieve the correct information (except for modules):这是一个将检索正确信息的函数(模块除外):
Public Function fGetObjectModifiedDate(Object_Name As String, Object_Type As Integer) As Variant
' Get the correct Modified Date of the passed object. MSysObjects and DAO are not accurate for all object types.
' Based on a tip from Philipp Stiefel <https://codekabinett.com>
' Getting the last modified date with this line of code does indeed return incorrect results.
' ? CurrentDb.Containers("Forms").Documents("Form1").LastUpdated
'
' But, that is not what we use to receive the last modified date, except for queries, where the above line is working correctly.
' What we use instead is:
' ? CurrentProject.AllForms("Form1").DateModified
Select Case Object_Type
Case 5 ' Query
fGetObjectModifiedDate = CurrentDb.QueryDefs(Object_Name).LastUpdated
Case -32768 ' Form
fGetObjectModifiedDate = CurrentProject.AllForms(Object_Name).DateModified
' fGetObjectModifiedDate = CurrentDb.Containers("Forms").Documents(Object_Name).LastUpdated
Case -32764 ' Report
fGetObjectModifiedDate = CurrentProject.AllReports(Object_Name).DateModified
Case -32766 ' Macro
fGetObjectModifiedDate = CurrentProject.AllMacros(Object_Name).DateModified
Case -32761 ' Module
' This will report the date that *ANY* module was last saved.
' The CurrentDb.Containers method and MSysObjects will report the date created.
fGetObjectModifiedDate = CurrentProject.AllModules(Object_Name).DateModified
Case Else
' Do nothing. Return Null.
End Select
End Function
Disclaimer: I am referencing the answer to a similar question that I had posted.免责声明:我引用了我发布的类似问题的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.