LastModified Property

Applies To

Dynamic-Type Recordset object, Dynaset-Type Recordset object, Recordset object, Snapshot-Type Recordset object, Table-Type Recordset object.

Description

Returns a bookmark indicating the most recently added or changed record.

Return Values

The return value is a Variant array of Byte data.

Remarks

You can use the LastModified property to move to the most recently added or updated record. Use the LastModified property with table- and dynaset-type Recordset objects. A record must be added or modified in the Recordset object itself in order for the LastModified property to have a value.

See Also

Bookmark property, Bookmarkable property, DateCreated, LastUpdated properties.

Specifics (Microsoft Access)

When you use the LastModified property in a Microsoft Access module, you must include an Option Compare Binary statement in the Declarations section of the module. The bookmark returned by the LastModified property is a Variant array of Byte data, so the string comparison method for the module must be binary. If a bookmark is evaluated with a text-based string comparison method, such as the Option Compare Text statement or the default setting for the Option Compare Database statement, the current record may be set to an incorrect record.

Example

This example uses the LastModified property to move the current record pointer to both a record that has been modified and a newly created record.

Sub LastModifiedX()

    Dim dbsNorthwind As Database
    Dim rstEmployees As Recordset
    Dim strFirst As String
    Dim strLast As String

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    Set rstEmployees = _
        dbsNorthwind.OpenRecordset("Employees", _
        dbOpenDynaset)

    With rstEmployees
        ' Store current data.
        strFirst = !FirstName
        strLast = !LastName
        ' Change data in current record.
        .Edit
        !FirstName = "Julie"
        !LastName = "Warren"
        .Update
        ' Move current record pointer to the most recently
        ' changed or added record.
        .Bookmark = .LastModified
        Debug.Print _
            "Data in LastModified record after Edit: " & _
            !FirstName & " " & !LastName

        ' Restore original data because this is a demonstration.
        .Edit
        !FirstName = strFirst
        !LastName = strLast
        .Update

        ' Add new record.
        .AddNew
        !FirstName = "Roger"
        !LastName = "Harui"
        .Update
        ' Move current record pointer to the most recently
        ' changed or added record.
        .Bookmark = .LastModified
        Debug.Print _
            "Data in LastModified record after AddNew: " & _
            !FirstName & " " & !LastName

        ' Delete new record because this is a demonstration.
        .Delete
        .Close
    End With

    dbsNorthwind.Close

End Sub
Example (Microsoft Access)

The following example determines the most recently modified record in a recordset and sets a bookmark for that record:

Sub LastChangedRecord()
    Dim dbs As Database, rst As Recordset, varBook As Variant

    ' Return reference to current database.
    Set dbs = CurrentDb
    ' Create dynaset-type Recordset object.
    Set rst = dbs.OpenRecordset("SELECT * FROM Orders " & _
        "ORDER BY ShipCountry;")
    With rst
        .FindFirst "ShipCountry = 'UK'"
        ' Alter record and save changes.
        .Edit
        !ShipCountry = "USA"
        .Update
    End With
    ' Check to see if recordset supports bookmarks.
    If rst.Bookmarkable Then
        ' Set bookmark to most recently modified record.
        varBook = rst.LastModified
        ' Set currency to last modified record.
        rst.Bookmark = varBook
    End If
    rst.Close
    Set dbs = Nothing
End Sub