LastModified Property 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