【问题标题】:How to compare MS-Access created and last modified dates of tables, queries, forms, etc.?如何比较表、查询、表单等的 MS-Access 创建日期和上次修改日期?
【发布时间】:2015-07-11 10:47:12
【问题描述】:

我喜欢在 Access 2010 数据库中创建和更新表、查询、表单等时创建一个列表。

理论上,使用一点 VBA 代码就可以做到这一点,但不幸的是,这段代码显示了错误的信息。我自己测试过,微软在这里确认了:https://support.microsoft.com/en-us/kb/299554

Access 在导航面板上显示正确的修改日期,但似乎无法通过 VBA 或任何表格访问此信息。前段时间我在互联网上搜索了这个问题,有几个人确认了这个问题,但没有人给出答案。

现在我的问题是:有人知道如何从 Access 中导出正确的修改日期信息(显示在导航面板中)吗?

如果这是不可能的(我目前的研究表明这一点)有没有人知道一种可靠的方法来比较一个数据库文件和另一个数据库文件并显示表、查询、表单等方面的所有差异?

这完全是关于 Access 对象的设计,而不是关于存储在表中的任何数据。

【问题讨论】:

    标签: vba ms-access datemodified


    【解决方案1】:

    该链接文章描述了为什么 LastUpdated 属性不能为您提供所需的数据库对象(例如表单和报表)。不幸的是,它并没有告诉您可以使用适当的CurrentProject 集合中的DateModified 来处理这些。

    例如,考虑一下导航窗格中表单的截屏:

    在 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
    

    但是,DateModifiedCurrentProject.AllForms 集合中为您提供了显示在导航窗格中的值:

    ? CurrentProject.AllForms("Form1").DateModified
    7/1/2015 6:47:40 AM 
    

    注意你也可以通过AllForms获得DateCreated

    ? CurrentProject.AllForms("Form1").DateCreated
    8/20/2012 10:51:07 PM 
    

    其他CurrentProject 集合包括:AllMacrosAllModules;和AllReports。注意模块是一起保存的,所以DateModified 会显示项目上次保存的时间。这意味着每个模块将在同一时间显示,与在导航窗格中显示的时间相同。

    【讨论】:

    • 谢谢,这将使我的生活更轻松。我想知道为什么 MS 不发布这些重要信息。
    【解决方案2】:

    这是一个检索正确信息的函数(模块除外):

    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
    

    免责声明:我引用了我发布的类似question 的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-01-28
      • 2012-08-02
      相关资源
      最近更新 更多