DateCreated, LastUpdated Properties

Applies To

Document object, QueryDef object, Recordset object, Table-Type Recordset object, TableDef object.

Description

  • DateCreated — returns the date and time that an object was created, or the date and time a base table was created if the object is a table-type Recordset object (Microsoft Jet workspaces only).
  • LastUpdated — returns the date and time of the most recent change made to an object, or to a base table if the object is a table-type Recordset object (Microsoft Jet workspaces only).
Return Values

The return value is a Variant (Date/Time subtype).

Remarks

For table-type Recordset objects, the date and time settings are derived from the computer on which the base table was created or last updated. For other objects, DateCreated and LastUpdated return the date and time that the object was created or last updated. In a multiuser environment, users should get these settings directly from the file server to avoid discrepancies in the DateCreated and LastUpdated property settings.

Example

This example demonstrates the DateCreated and LastUpdated properties by adding a new Field to an existing TableDef and by creating a new TableDef. The DateOutput function is required for this procedure to run.

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
Example (Microsoft Access)

The following example enumerates through all QueryDef objects in the database and lists those which have been created or changed within the last sixty days:

Sub TimeUpdated()
    Dim dbs As Database, tdf As TableDef, qdf As QueryDef
    Dim strList As String, dteWeek As Date

    ' Return reference to current database.
    Set dbs = CurrentDb
    dteWeek = Now - 60
    ' Enumerate through QueryDefs collection.
    For Each qdf In dbs.QueryDefs
        ' Evaluate LastUpdated and DateCreated properties.
        If (qdf.LastUpdated > dteWeek) Or (qdf.DateCreated > dteWeek) 
            Then
            ' Create list.
            strList = strList & vbCrLf & qdf.Name
        End If
    Next qdf
    MsgBox strList
    Set dbs = Nothing
End Sub
Example (Microsoft Excel)

This example displays the dates and times when the Customer recordset in the Nwindex.mdb database was created and last updated.

To create the Nwindex.mdb database, run the Microsoft Excel example for the CreateDatabase method.

Dim creation As Variant, changed As Variant
Dim db As Database, td As TableDef
Set db = Workspaces(0).OpenDatabase(Application.Path & "\NWINDEX.MDB")
Set td = db.TableDefs("Customer")
creation = td.DateCreated
changed = td.LastUpdated
MsgBox "The " & td.Name & " table was created on " & creation _
    & " and updated on " & changed
db.Close