Suivre les modifications de conception apportées à un jeu d’enregistrements DAO de type table

Il peut être nécessaire de déterminer la date de création ou de modification de l'objet TableDef d'un objet Recordset de type table. Les propriétés DateCreated et LastUpdated, vous offre ces informations, respectivement. Elles renvoient toutes deux l'horodatage appliqué à la table par la machine sur laquelle se trouvait la table à ce moment-là. Ces propriétés ne sont mises à jour qu'en cas de modifications de structure de la table, ce qui exclut donc les modifications des enregistrements de la table.

L’exemple de code suivant montre les propriétés DateCreated et LastUpdated en ajoutant un nouveau Champ à un TableDef existant et en créant un nouveau TableDef. La fonction DateOutput est nécessaire à l'exécution de cette procédure.

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

Assistance et commentaires

Avez-vous des questions ou des commentaires sur Office VBA ou sur cette documentation ? Consultez la rubrique concernant l’assistance pour Office VBA et l’envoi de commentaires afin d’obtenir des instructions pour recevoir une assistance et envoyer vos commentaires.