Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easiest way to create save changes before closing a from.

Status
Not open for further replies.

kkgusta

MIS
Nov 10, 2005
42
NZ
Hi there,
Is anyone here know the easiest way to create a save changes before closing an unbound from. Like when you are in an edit or add new mode and you choose to close the form and a message box will pop up and prompt user to save the change before it close the form. Currently I am trying to add a long list of code in all closing event in my forms and this have causing me a lot of trouble and time consuming. Therefore I am trying to look for a better way to do this.
 
Have you seen?
KISS way to force users to click a command button to exit a form regardless of menu or toolbar options
faq702-2071

 
Something like this in the form's BeforeUpdate event works well for bound forms. You may be able to adapt it for unbound.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Select Case MsgBox("Do you want to save changes to this record?", vbYesNoCancel + vbQuestion)
    Case vbYes 'Go-ahead and save
        'Don't have to do anything
    Case vbNo 'Undo all changes, close without saving
        Me.Undo
    Case Else 'Cancel change, continue editing
        Cancel = True
    End Select
End Sub

[pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top