Recordset.LastModified プロパティ (DAO)

適用先: Access 2013、Office 2013

最後に追加または変更されたレコードを示すブックマークを返します。

構文

式 。Lastmodified

expression: Recordset オブジェクトを表す変数。

注釈

LastModified プロパティを使用すると、最後に追加または更新したレコードに移動できます。 LastModified プロパティは、テーブル タイプおよびダイナセット タイプの Recordset オブジェクトで使用します。 LastModified プロパティに値を設定するには、 Recordset オブジェクト自体に対してレコードの追加または変更を行う必要があります。

例

この例では、LastModified プロパティを使用して、カレント レコードを参照するポインターを、変更したレコードおよび新しく作成したレコードの両方に移動します。

Public Sub LastModifiedDemo() 
    
    Dim Northwind           As DAO.Database 
    Dim Employees           As DAO.Recordset 
    Dim CurrentFirstName    As String 
    Dim CurrentLastName     As String 
    
    Set Northwind = OpenDatabase("Northwind.mdb") 
    Set Employees = Northwind.OpenRecordset("Employees", dbOpenDynaset) 
    
    With Employees 
        ' Store current data. 
        CurrentFirstName = !FirstName 
        CurrentLastName = !LastName 

        ' Modify the data in the current record. 
        .Edit 
            !FirstName = "Julie" 
            !LastName = "Warren" 
        .Update 
        ' Move the current record pointer to the most recently 
        ' modified or added record. 
        .Bookmark = .LastModified 
        Debug.Print _ 
            "Data in LastModified record after Edit: " & _ 
            !FirstName & " " & !LastName 
        
        ' Restore the original data because this is a demonstration. 
        .Edit 
            !FirstName = CurrentFirstName 
            !LastName = CurrentLastName 
        .Update 
        
        ' Add new record. 
        .AddNew 
            !FirstName = "Roger" 
            !LastName = "Harui" 
        .Update 
        ' Move the current record pointer to the most recently 
        ' modified or added record. 
        .Bookmark = .LastModified 
        Debug.Print _ 
            "Data in LastModified record after AddNew: " & _ 
            !FirstName & " " & !LastName 
        
        ' Delete the new record because this is a demonstration. 
        .Delete 
        .Close 
    End With 
    Set Employees = Nothing

    Northwind.Close 
    Set Northwind = Nothing
 
End Sub 

この例では、 AddNew メソッドを使用して、指定した名前を持つ新しいレコードを作成します。 このプロシージャを実行するには、AddName サブが必要です。

Public Sub AddNewDemo() 
 
    Dim Northwind       As DAO.Database 
    Dim Employees       As DAO.Recordset 
    Dim FirstName       As String 
    Dim LastName        As String 
    
    Set Northwind = OpenDatabase("Northwind.mdb") 
    Set Employees = Northwind.OpenRecordset("Employees", dbOpenDynaset) 
    
    ' Get data from the user. 
    FirstName = Trim(InputBox("Enter first name:")) 
    LastName = Trim(InputBox("Enter last name:")) 
    
    ' Proceed only if the user actually entered something 
    ' for both the first and last names. 
    If FirstName <> "" And LastName <> "" Then        
        ' Call the sub that adds the record. 
        AddName Employees, FirstName, LastName 
        
        ' Show the newly added data. 
        With Employees 
            Debug.Print _ 
                "New record: " & !FirstName & " " & !LastName 
            ' Delete the new record because this is a demonstration. 
            .Delete 
        End With             
    Else 
        MsgBox _ 
            "You must input values for both first and last name.", _
            vbInformation + vbOKOnly, _
            "Add new name" 
    End If 
    
    Employees.Close 
    Set Employees = Nothing

    Northwind.Close 
    Set Northwind = Nothing
 
End Sub 

 
Public Sub AddName( _ 
    ByRef Records As DAO.Recordset, _ 
    ByVal FirstName As String, _ 
    ByVal LastName As String) 
    
    ' Adds a new record to a Recordset using the data 
    ' passed by the calling procedure. 
    ' The new record is then made the current record. 
    With Records 
        .AddNew 
            !FirstName = FirstName 
            !LastName = LastName 
        .Update 
        .Bookmark = .LastModified 
    End With 
 
End Function