P
Paul Ponzelli
I've got a command label on a form captioned "Return to Main Menu."
In the click event of that label, I check to see if an unsaved change has
been made to the data, and if so, I ask the user whether to save or abandon
the changes. The portion that saves the changes works fine, but I can't
seem to get the code to cancel the change if the user doesn't want to save
them.
Here's the code I'm using:
If Me.Dirty Then
If MsgBox("Do you want to save the change(s) you made to this
application?" & vbCr & vbCr & _
"Click 'Yes' to save your changes, 'No' to close without saving.", _
vbYesNo, "Save Changes?") = vbYes Then
'Do this if user clicks "Yes" to save the record.
DoCmd.RunCommand acCmdSaveRecord
Me!cmdSaveRecord.Visible = False
Else
'Do this if user clicks "No" to cancel the changes.
SendKeys "{esc}{esc}"
End If
End If
When this code executes and the user clicks "No," the record saves anyway.
Any suggestions on how to modify this code so that the changes are cancelled
when the user clicks "No?"
Thanks in advance,
Paul
In the click event of that label, I check to see if an unsaved change has
been made to the data, and if so, I ask the user whether to save or abandon
the changes. The portion that saves the changes works fine, but I can't
seem to get the code to cancel the change if the user doesn't want to save
them.
Here's the code I'm using:
If Me.Dirty Then
If MsgBox("Do you want to save the change(s) you made to this
application?" & vbCr & vbCr & _
"Click 'Yes' to save your changes, 'No' to close without saving.", _
vbYesNo, "Save Changes?") = vbYes Then
'Do this if user clicks "Yes" to save the record.
DoCmd.RunCommand acCmdSaveRecord
Me!cmdSaveRecord.Visible = False
Else
'Do this if user clicks "No" to cancel the changes.
SendKeys "{esc}{esc}"
End If
End If
When this code executes and the user clicks "No," the record saves anyway.
Any suggestions on how to modify this code so that the changes are cancelled
when the user clicks "No?"
Thanks in advance,
Paul