Closing a Form and Cancelling the Record

D

David

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.
 
M

Marshall Barton

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 ;-)
 
G

G. Vaught

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top