RE: Confirm data change on close
- From: Klatuu <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 9 Jun 2008 06:44:01 -0700
I'm not sure what you are saying.
Docmd.Close should fire the Form Before Update, After Update, Unload, and
Close events in that order.
--
Dave Hargis, Microsoft Access MVP
"RickW" wrote:
This method isn't working for me!.
I am finding that the forms Dirty property is changed to False by
DoCmd.Close so the code in Form_UnLoad never recognises an unsaved record.
I feel I getting no where! Hope you can help!
Regards
Rick
"Klatuu" wrote:
For your save button:
If Me.Dirty Then
Me.Dirty = False
End If
For your Exit Button, just use Docmd.Close in the click event. Put the code
to check for changes in the Form's Unload event. That way, if the user
closes the form either using the exit button or by some other means, it will
stilll do the check.
Put this in the Form Unload event:
Dim str Msg As String
If Me.Dirty Then
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?"
strMsg = strMsg & " Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
Me.Dirty = False
Else
Me.Undo
End If
End If
--
Dave Hargis, Microsoft Access MVP
"Travis (New User)" wrote:
Alright guys, thanks for all the help. All of your answers put me in the
right direction. I didn't do a very good job explaining exactly what I
wanted, but here is the code that I came up with after all of your
suggestions that works:
If Me.Dirty Then
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?"
strMsg = strMsg & " Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
Then
'do nothing
DoCmd.Close
Else
Me.Undo
DoCmd.Close
End If
Else
'do nothing
DoCmd.Close
End If
On a form I have a close button, a save button, text boxes, drop down lists,
etc etc. I have taken away the microsoft given buttons at the top. The only
way for the user to interact with the form is by the objects I have given
them.
I wanted the save button to save the record automatically with no prompting,
but I wanted the exit button to check if there were any accidental changes
and ask the user to confirm what they wanted.
Again, thanks for all the help guys. You all got me on the right path!
- Travis
"Travis (New User)" wrote:
I want a data editing form to check for changes when the close button is
pressed by the user. The code I have entered reads "Run time error 13. Type
Mismatch" Any help would be greatly appreciated!
Private Sub Form_Close()
If Me.DataChange Then
Dim strMsg As String
Dim Cancel As Integer
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?"
strMsg = strMsg & " Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
Then
'do nothing
Else
Me.Undo
Cancel = True
End If
Else
'do nothing
End If
End Sub
- Follow-Ups:
- RE: Confirm data change on close
- From: RickW
- RE: Confirm data change on close
- References:
- RE: Confirm data change on close
- From: RickW
- RE: Confirm data change on close
- Prev by Date: shortcut menu and popup modal form
- Next by Date: Foreign name changes to English word when entered on form
- Previous by thread: RE: Confirm data change on close
- Next by thread: RE: Confirm data change on close
- Index(es):