Form.
You can use the Dirty property to determine whether the current record has been modified since it was last saved. For example, you may want to ask the user whether changes to a record were intended and, if not, allow the user to move to the next record without saving the changes.
The Dirty property has the following settings.
Setting | Description | Visual Basic |
True | The current record has been changed. | True (-1) |
False | The current record has not been changed. | False (0) |
This property is available only in Form view and Datasheet view.
This property is read-only and available only in a macro or using Visual Basic.
When a record is saved, the Dirty property is automatically set to False. When a user makes changes to a record, the property is set to True.
The following example enables the btnUndo button when data is changed. The UndoEdits( ) subroutine is called from the AfterUpdate event of text box controls. Clicking the enabled btnUndo button restores the original value of the control using the OldValue property.
Sub UndoEdits() If Me.Dirty Then Me!btnUndo.Enabled = True ' Enable button. Else Me!btnUndo.Enabled = False ' Disable button. End IfSub btnUndo_Click() Dim intNumControls As Integer, i As Integer Dim C As Control intNumControls = Forms!EditForm.Count For i = 0 to intNumControls - 1 ' For each control. Set C = Forms!EditForm(i) If TypeOf C Is TextBox Then ' If control is TextBox. C.Value = C.OldValue ' Restore Old Value. End If Next iSub