Msg box on close only if in edit mode

cubbyamber

Registered User.
Local time
Yesterday, 22:22
Joined
Aug 28, 2006
Messages
60
I have a form that is locked unless they click the command button to edit records. I want a msg box that when they click the close button it pops up with something like save edits? Just as an extra precaution. But I only want the message box to pop up if the form is in edit mode. Is this possible? And I would like to be able to have them click ok or cancel in the message box

Here is the code for the close button:

Private Sub Close_Click()
On Error GoTo Err_Close_Click


DoCmd.Close

Exit_Close_Click:
Exit Sub

Err_Close_Click:
MsgBox Err.Description
Resume Exit_Close_Click

End Sub

Thanks

Tracy
 
You can put your code in the BeforeUpdate event since Access will attempt to save the record if it is Dirty.
 
okay did that worked like a charm I also made it a yes no msg box but when it pops up even if I select no, it still saves it and I want it to reset the form

Here is my code

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Save Edits?", vbYesNo, "Exit") = vbYes Then DoCmd.Close

End Sub

Tracy
 
cubbyamber said:
okay did that worked like a charm I also made it a yes no msg box but when it pops up even if I select no, it still saves it and I want it to reset the form

Here is my code

Private Sub Form_BeforeUpdate(Cancel As Integer)

If MsgBox("Save Edits?", vbYesNo, "Exit") = vbYes Then DoCmd.Close

End Sub

Tracy
You have to cancel the event if you do not want the changes saved to the current record.

Code:
If MsgBox("Save changes to current record?", vbYesNo, "Save Edits") = vbNo Then
     Docmd.CancelEvent
End If
I suggest that you check out these threads for they will help you do what you want...

A Better Mouse Trap?

Enable/Disable The Control Box X Button

Audit Trail
 
Thank you.

I did look at the mouse trap thread as I was trying to figure out the scrolling thing but I have to look more in depth.

Again, thank you.

Tracy
 

Users who are viewing this thread

Back
Top Bottom