On a data entry form, I have a "Close" button (cmdClose) that, upon clicking, will ask if the user would like to save or discard the changes.
This is fine, except if the user has accidentally opened the form and would like to close it. When the form is opened, unchanged, and then the Close button is clicked- The message box comes up and asks if the user would like to save the changes. Of course, there are no changes, so the user would click "No".
Unfortunately, this causes an error "The command or action 'Undo' isn't available now."
Is there some sort of way to add a command that says 'don't ask if the form didn't get dirty' or suppress this one error message?
Here is my code for this button:
Code:
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
Dim stDocName As String
Dim stMsg As String
strMsg = "Do you wish to save the changes?"
strMsg = strMsg & vbNewLine & "Click 'Yes' to save changes or 'No' to discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Changes?") = vbYes Then 'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If
DoCmd.Close
stDocName = "Frm00_MainMenu"
DoCmd.OpenForm stDocName
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
Thanks!