I've created 2 buttons that I've placed on all my forms: a Save button & a Cancel button.
The cancel button I have a question about.
I used the wizard to create the button and I selected the Record Operations/Undo Record option. I edited the vba code to have the button also close the form after it undoes any changes. Here is the actual code for the OnClick event for the cancel button:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdCancel_Click()
- On Error GoTo errHandle
- Dim intProcced As Integer
- 'Warn the user that any information entered will be lost, then if the user responds that it is
- 'ok, erase the record and close the form
- intProcced = MsgBox("Warning: Any changes made or any information entered will not be saved.", vbOKCancel, "Warning")
- If intProcced = 2 Then
- Exit Sub
- End If
- DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer1X
- DoCmd.Close
- Exit Sub
- errHandle:
- If Err.Number = 2046 Then
- DoCmd.Close
- Exit Sub
- Else
- 'Print the error message and send an email to Administrator
- SendErrorMsg "cmdCancel_Click on frmEnterNewFeeder", Err.Number, Err.Description
- MsgBox Err.Description
- End If
- Exit Sub
- End Sub
"The command or action Undo isn't available now."
Which is true, nothing was done to "undo". What I want the button to do, is undo only if a change has been made. How can I (in the vba code) check first that a change has been made on the form and only execute the undo if a change has been made, otherwise I just want to close the form.
The Error checking and check for the error condition and ignore it code that I have there doesn't work!
Thank so much for your help!