DateCreated, LastUpdated Properties 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