Form Closing

ramhanuman

Registered User.
Local time
Yesterday, 18:36
Joined
May 1, 2012
Messages
13
My goal is to prevent anything from saving to the database if the user just hits the close button on the top right of the form. I'm not positive but I believe the form calls the Close command when you click the X, so I tried something like this

Private Sub Form_Close()
Form.Dirty = False
End Sub

But the record still gets saved into the database. So how can I make it so that when the user clicks the close button it just closes and doesn't save anything? Thank you
 
Best approach is to always ask the user whether they want to save a new record or save changes made in an existing record.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
 If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
  Me.Undo
 End If
Else
 If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
  Me.Undo
 End If
End If
End Sub
Linq ;0)>
 
Let's say the user hits the close button and I have a msgbox that asks if the user really wants to exit and the user doesn't. If he/she clicks no, how do I stop the form from closing?
 

Users who are viewing this thread

Back
Top Bottom