Exit without saving

dsetiadi

College Student
Local time
Today, 12:51
Joined
Aug 12, 2005
Messages
7
I am trying to give a warning message like in microsoft word. When the user made some change in the form, and then unload the form, I will give the user a message: exit and saved the changes, exit without saving, or cancel. Apparently, the exit without saving never works out. Here is my code:

If Me.DataIsChanged = -1 Then
Dim Msg, Style, Title, Response

' Define message.
Msg = "Do you want to save the changes you made to 'Turbosteam Service History Database'?"
Style = vbYesNoCancel + vbExclamation + vbDefaultButton1 ' Define buttons.
Title = "Exiting Projects form" ' Define title.

Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
DoCmd.Close acForm, 2, acSaveYes 'Exit with the saving the changes
Else
If Response = vbNo Then
'DoCmd.Close acForm, 2, acSaveNo 'I tried to use this, but didn't work either
Me.ExitWithoutSaving
Else
DoCmd.CancelEvent 'Cancel exit action and go back to form
End If
End If
End If

Can anybody help please?

Dedi
 
Did you try searching the forum?

Enable/Disable The Control Box X Button

The form named "fTestCancelFromUnloadEvent" in the sample db will demonstrate how you can prevent a user from closing a form and also the application unless they do exactly what you want them to do.

You have to use the forms BeforeUpdate event to validate the users data!
 

Users who are viewing this thread

Back
Top Bottom