Dirty Event — Event Procedures Example

The following example enables the btnUndo button when data is changed. The UndoEdits( ) subroutine is called from the Dirty event of text box controls. Clicking the enabled btnUndo button restores the original value of the control by using the OldValue property.

Private Sub Form_Dirty()
    If Me.Dirty Then
        Me!btnUndo.Enabled = True    ' Enable button.
    Else
        Me!btnUndo.Enabled = False    ' Disable button.
    End If
End Sub

Sub btnUndo_Click()
    Dim ctlC As Control
        ' For each control.
        For Each ctlC in Me.Controls
            If ctlC.ControlType = acTextBox Then
                ' Restore Old Value.
                ctlC.Value = ctlC.OldValue
            End If
        Next ctlC
End Sub