Previous Page
Next Page

Hack 24. Confirm Record Updates Before Saving

Give users a chance to review their edits before they save a record.

When you're working on a bound form, as you scroll through records, data changes are saved automatically. This behavior is normal and is often appreciated rather than questioned. However, sometimes it is prudent to interrupt this process and let a user review her work. Once the update happens, the original data is gone, unless other measures, such as backups, are in place.

One thing that works in our favor to control this is the Before Update event. By hooking into this event, you can ask the user whether she wants to complete the update. If the answer is no, you undo the changes.

Users should control whether they want to be prompted to confirm changes because the prompts can become annoying. A user might want this feature sometimes but not other times. Figure 3-20 shows a form with a checkbox in the upper-right section that acts as a flag indicating whether to confirm updates.

Figure 3-20. A checkbox to indicate whether to confirm updates


The Before Update event fires only when the data changes. In the event, the checkbox value is tested, and if the value is true, the user is prompted. Figure 3-21 shows the prompt.

If the user clicks Yes, the update proceeds. If she clicks No, an undo command runs, thereby dropping the changes to the data. Here is the event and the code:

	Private Sub Form_BeforeUpdate(Cancel As Integer)
      If Me.chkConfirm = True Then
        proceed = MsgBox("Do you want to save the changes?", vbYesNo, _
          "Save Changes")
        If proceed = vbNo Then
          DoCmd.RunCommand acCmdUndo
        End If
      End If
    End Sub

A key point to this hack is letting the user decide whether to be prompted. Being asked to confirm endless changes will quickly become a source of frustration. The nice thing is that users can decide to turn on the feature when updating critical information, such as names and addresses, but turn off the feature when making changes to less important data.

Figure 3-21. Confirming an update


    Previous Page
    Next Page