Closing a Form and Cancelling the Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to add a button on my form that will cancel any data entered on the
form - before the record has been saved, and close the form. How can I do
this?

Thanks.
 
David said:
I want to add a button on my form that will cancel any data entered on the
form - before the record has been saved, and close the form. How can I do
this?


Add the line:

DoCmd.Close acForm, Me.Name

to my reponse to your other question ;-)
 
Create a button add this code against the button's OnClick Event:
Private Sub cmdUndo_Click()
On Error GoTo Err_cmdUndo_Click

'Note: This will not stop an autonumber key from incrementing. Not sure how
to stop that.

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70 ' Undo our
record
DoCmd.CancelEvent ' Cancel our event so we don't get an error msg.
DoCmd.GoToRecord , , acLast ' returns back to the last record before
closing
DoCmd.Close , frmCustomers ' closes the form


Exit_cmdUndo_Click:
Exit Sub

Err_cmdUndo_Click:
MsgBox Err.Description
Resume Exit_cmdUndo_Click

End Sub
 
Back
Top