Save changes when closing

Medea

Registered User.
Local time
Yesterday, 21:39
Joined
Oct 18, 2007
Messages
19
Hello All,

I have a close button on my form that if the user has made changes, a message box pops up asking if they want to save the changes. That works fine. See below...

Private Sub cmd_Close_Click()

If (Me.Dirty = True) Then
If MsgBox("Do you want to save your changes?", vbYesNo + vbInformation, "Close") = vbYes Then
DoCmd.Close acForm, Me.Name
Else
Me.Undo
DoCmd.Close acForm, Me.Name

End If
End If

End Sub

What I can't figure out is how to bypass all of the code and just close the form if the user has not made any changes to the record. None of the records in this table are new.

Am I going about this the wrong way? Maybe there is a simpler solution. All ideas or suggestions welcome.

Thanks,

Trish
 
Between your two End If's put this:

Code:
   End If
Else
  DoCmd.Close acForm, Me.Name
End If
 
You need an "Else" clause to your original If (Me.Dirty = True)
Code:
Private Sub cmd_Close_Click()

If (Me.Dirty = True) Then
  If MsgBox("Do you want to save your changes?", vbYesNo + vbInformation, "Close") = vbYes Then
     DoCmd.Close acForm, Me.Name
  Else
    Me.Undo
    DoCmd.Close acForm, Me.Name
  End If
[B]Else
  DoCmd.Close acForm, Me.Name
[/B]End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom