Cancelling a new record addition

G

Guest

I have a form in which at times the user would want to cancel any of the data
that has already been entered. I created a Cancel button that has the
accompanying code. What is supposed to happen is the form that is open in add
mode is closed and not saved, then my main switchboard form is opened, but no
matter what, a new record is added to the Table that is associted with the
report. I think I've determined that it has something to do with a macro that
I'm running on the form that is being called by the OnCurrent event when it
is opened. I kind of need to have the macro run so is there another way of
making a cancel button work? I'm somewhat of a newbie to coding so bear with
me. Thanks in advance.

Private Sub Cancel_Click()
On Error GoTo Err_Cancel_Click

DoCmd.Close acForm, "frmReport", acSaveNo
DoCmd.OpenForm "Main Switchboard"

Exit_Cancel_Click:
Exit Sub

Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click
End Sub
 
A

Allen Browne

Access saves each record before moving on to the next. If a record has not
been saved yet, you could use the Undo method of the form:

If Me.Dirty Then
Me.Undo
End If
DoCmd.OpenForm "Main Switchboard"
DoCmd.Close acForm, Me.Name

Note that the acSaveNo does not affect saving the record. It refers only to
saving any design changes in the form.
 
G

Guest

Thanks, Worked perfectly....

Allen Browne said:
Access saves each record before moving on to the next. If a record has not
been saved yet, you could use the Undo method of the form:

If Me.Dirty Then
Me.Undo
End If
DoCmd.OpenForm "Main Switchboard"
DoCmd.Close acForm, Me.Name

Note that the acSaveNo does not affect saving the record. It refers only to
saving any design changes in the form.
 

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