Cancel or Apply Now button

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

Guest

I'm opening a form to edit a set of address records. We want our users to be able to back out of the form without applying the changes, especially a new record

The classic "Cancel" button is what we want, but it appears that after a button is assigned as a "cancel" button, you still need to code the cancel event. I haven't seen any explanation yet. Any help?
 
Unless the record has already been saved, this code should work in the
Cancel button:
Private Sub cmdCancel_Click()
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
End Sub



--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

robott said:
I'm opening a form to edit a set of address records. We want our users to
be able to back out of the form without applying the changes, especially a
new record.
The classic "Cancel" button is what we want, but it appears that after a
button is assigned as a "cancel" button, you still need to code the cancel
event. I haven't seen any explanation yet. Any help?
 
One thing to be aware of is that if you are using a main form sub form setup
and you are editing/adding a record on your sub form, but the cancel button
is on your main form then once you tab out of the subform or click the
cancel button the record on the subform will be saved. If this is the case
you could use something like this in the BeforeUpdate event on you subform.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then
If MsgBox("Do you want to Save?", vbQuestion + vbYesNo, "Save Record") =
vbNo Then
Me.Undo
End If
End If
End Sub
 
Back
Top