4

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

从理论上讲,这可以通过一点 VBA 代码实现,但不幸的是,该代码显示了错误的信息。我自己测试过,微软在此确认:https: //support.microsoft.com/en-us/kb/299554

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

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

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

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

4

2 回答 2

5

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

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

显示表单的导航窗格

在 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

但是DateModified,对于CurrentProject.AllForms集合中的同一个表单,您会得到导航窗格中显示的值:

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

请注意,您还可以DateCreated通过以下方式获得AllForms

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

其他CurrentProject收藏包括AllMacrosAllModules; 和AllReports。请注意,模块是一起保存的,因此会DateModified向您显示项目上次保存的时间。这意味着每个模块将在同一时间显示,与导航窗格中显示的相同。

于 2015-07-12T13:58:23.770 回答
1

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

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

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

于 2019-07-23T12:49:27.003 回答