Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: Ask before saving record

Author(s)
Dev Ashish

(Q)    How can I control when a record is saved in a form? 

(A)    Use the form's BeforeUpdate event to run code each time Access tries to save a record.  This way, if the user doesn't want to save a record,   you can issue an Undo command instead of saving the record.

Note:  This will generate a Message Box asking for confirmation each time a changed record is saved.  I leave it on whoever is going to follow this method to determine how to refine this per user preference. (Hint: Try a Checkbox.)

'****************** Code Start ******************
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
    strMsg = "Data has changed."
    strMsg = strMsg & "@Do you wish to save the changes?"
    strMsg = strMsg & "@Click Yes to Save or No to Discard changes."
    If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
        'do nothing
    Else
        DoCmd.RunCommand acCmdUndo
        
        'For Access 95, use DoMenuItem instead
        'DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    End If
End Sub
'****************** Code End ******************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer