EditMode Property

Applies To   Dynamic-Type Recordset object, Dynaset-Type Recordset object, Forward-Only–Type Recordset object, Recordset object, Snapshot-Type Recordset object, Table-Type Recordset object.

Description

Returns a value that indicates the state of editing for the current record.

Return Values

The return value is a Long that indicates the state of editing, as listed in the following table.

Constant

Description

dbEditNone

No editing operation is in progress.

dbEditInProgress

The Edit method has been invoked, and the current record is in the copy buffer.

dbEditAdd

The AddNew method has been invoked, and the current record in the copy buffer is a new record that hasn't been saved in the database.


Remarks   The EditMode property is useful when an editing process is interrupted, for example, by an error during validation. You can use the value of the EditMode property to determine whether you should use the Update or CancelUpdate method.

You can also check to see if the LockEdits property setting is True and the EditMode property setting is dbEditInProgress to determine whether the current page is locked.

See Also   AddNew method, CancelUpdate method, LockEdits property.

Example

This example shows the value of the EditMode property under various conditions. The EditModeOutput function is required for this procedure to run.

Sub EditModeX()

    Dim dbsNorthwind As Database
    Dim rstEmployees As Recordset

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

    ' Show the EditMode property under different editing
    ' states.
    With rstEmployees
        EditModeOutput "Before any Edit or AddNew:", .EditMode
        .Edit
        EditModeOutput "After Edit:", .EditMode
        .Update
        EditModeOutput "After Update:", .EditMode
        .AddNew
        EditModeOutput "After AddNew:", .EditMode
        .CancelUpdate
        EditModeOutput "After CancelUpdate:", .EditMode
        .Close
    End With

    dbsNorthwind.Close

End Sub

Function EditModeOutput(strTemp As String, _
    intEditMode As Integer)

    ' Print report based on the value of the EditMode
    ' property.
    Debug.Print strTemp
    Debug.Print "    EditMode = ";

    Select Case intEditMode
        Case dbEditNone
            Debug.Print "dbEditNone"
        Case dbEditInProgress
            Debug.Print "dbEditInProgress"
        Case dbEditAdd
            Debug.Print "dbEditAdd"
    End Select

End Function
Example (Microsoft Excel)

This example checks to see whether the Customer recordset in the Nwindex.mdb database can be edited. If so, the example updates the value of the first field in the first record with the value in cell C3 on Sheet1.

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

Dim db As Database, rs As Recordset
Set db = Workspaces(0).OpenDatabase(Application.Path & "\NWINDEX.MDB")
Set rs = db.OpenRecordset("Customer")
If Not ((rs.EditMode = dbEditAdd) Or _
        (rs.EditMode = dbEditInProgress)) Then
    rs.Edit
    rs.Fields(0).Value = Worksheets(1).Cells(3, 3).Value
    rs.Update
Else
    MsgBox ("Cannot update database with cell value")
End If
rs.Close
db.Close