Search code examples
ms-accessvbams-access-2016

How to ask a user to confirm edits to a record in access


I have a working access database that uses a multiple items form along with a search function in order to display records. I noticed that it was really easy to change information in a record without noticing.

Is there a way to ask a user if they're sure they want to make changes to a record before the table is updated?


Solution

  • This type of event can be handled with a simple response on save / update event.

    response = MsgBox("Save your record?", vbQuestion + vbYesNo, "Save Confirmation")
    If response = vbNo Then
        Cancel = True
        Me.Undo
    End If
    

    Cancel = True stops the record from being written and saved.
    Me.Undo reverts the changes to the source

    This would be handled through the BeforeUpdate event.

    Alternatively, this can be handled differently by using a specific save function for the form (where the form would otherwise never update the source), and simply posting a similiar confirmation where a vbYes results in a save.