简体   繁体   English

如何比较 MS-Access 创建和上次修改表格、查询、表单等的日期?

[英]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 集合中引用该表单时, LastUpdatedDateCreated都返回相同的值:

? 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.

相关问题 如何限制Ms-Access数据库表中的手动修改,但允许通过VBA脚本修改这些表? - How to restrict manual modification in Ms-Access database tables but allow these to be modified by VBA script? MS-Access并使用数字链接表格 - Ms-Access and using numbers to link forms ms-access:当我更改ACCDR表格/表格的扩展名时消失 - ms-access: when i change extension to ACCDR forms/tables disappear Ms Access - 删除所有表、查询、表单、报表和模块 - Ms Access - Delete all tables, queries, forms, reports and modules 如何在VBA中更改现有MS-ACCESS传递查询的ODBC连接字符串 - How do you alter the ODBC connection string for existing MS-ACCESS pass-through queries in VBA MS-Access按钮正在使用fileModDate = f.DateLastModified;如何将fileModDate与今天的日期进行比较 - MS-Access button is using fileModDate = f.DateLastModified;how do I compare the fileModDate to todays date 如何根据ms-access中的其他值以连续形式为每条记录填充文本框上的值 - How to fill value of on textbox based on value of other in ms-access in continuous forms for each record MS-Access:对链接的CSV文件进行慢速查询 - MS-Access: Slow queries on linked CSV files 如何摆脱使用“Transferdatabase”创建的 ms-access “幽灵模块” - How to get rid of a ms-access “ghost modules” which are created with “Transferdatabase” ms-access:如何进行正确的重新查询? - ms-access: how to do a proper requery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM