跟踪对表类型 DAO 记录集进行的设计更改

可能需要确定创建表类型 Recordset 的基础 TableDef 对象的时间,或者上次修改该对象的时间。 DateCreatedLastUpdated 属性分别提供此信息。 两个属性都返回日期戳,该日期戳由包含表的计算机在为该表加盖日期戳时应用于该表。 这些属性仅在表设计发生更改时更新;它们不受表中记录更改的影响。

下面的代码示例通过向现有 TableDef 添加新字段和创建新的 TableDef 来显示 DateCreatedLastUpdated 属性。 要使该过程运行,需要使用 DateOutput 函数。

Sub DateCreatedX() 
 
   Dim dbsNorthwind As Database 
   Dim tdfEmployees As TableDef 
   Dim tdfNewTable As TableDef 
 
   Set dbsNorthwind = OpenDatabase("Northwind.mdb") 
 
   With dbsNorthwind 
      Set tdfEmployees = .TableDefs!Employees 
 
      With tdfEmployees 
         ' Print current information about the Employees  
         ' table. 
         DateOutput "Current properties", tdfEmployees 
 
         ' Create and append a field to the Employees table. 
         .Fields.Append .CreateField("NewField", dbDate) 
 
         ' Print new information about the Employees  
         ' table. 
         DateOutput "After creating a new field", _ 
            tdfEmployees 
 
         ' Delete new Field because this is a demonstration. 
         .Fields.Delete "NewField" 
      End With 
 
      ' Create and append a new TableDef object to the  
      ' Northwind database. 
      Set tdfNewTable = .CreateTableDef("NewTableDef") 
      With tdfNewTable 
         .Fields.Append .CreateField("NewField", dbDate) 
      End With 
      .TableDefs.Append tdfNewTable 
 
      ' Print information about the new TableDef object. 
      DateOutput "After creating a new table", tdfNewTable 
 
      ' Delete new TableDef object because this is a  
      ' demonstration. 
      .TableDefs.Delete tdfNewTable.Name 
      .Close 
   End With 
 
End Sub 
 
Function DateOutput(strTemp As String, _ 
   tdfTemp As TableDef) 
 
   ' Print DateCreated and LastUpdated information about  
   ' specified TableDef object. 
   Debug.Print strTemp 
   Debug.Print "  TableDef: " & tdfTemp.Name 
   Debug.Print "    DateCreated = " & _ 
      tdfTemp.DateCreated 
   Debug.Print "    LastUpdated = " & _ 
      tdfTemp.LastUpdated 
   Debug.Print 
 
End Function

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。