Record is created Close/Save set No

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

When I close a form any data entered into that form is
still saved in the table even though I have the code

DoCmd.Close , POProducts, acSaveNo

I have also tried a DoCmd.CancelEvent. When the exit
button is clicked I want the form to close and no new
record created in the table. What is going on and why is
a new record being created when I don't want it to?
Thanks in advance.
 
Ron said:
When I close a form any data entered into that form is
still saved in the table even though I have the code

DoCmd.Close , POProducts, acSaveNo

I have also tried a DoCmd.CancelEvent. When the exit
button is clicked I want the form to close and no new
record created in the table. What is going on and why is
a new record being created when I don't want it to?
Thanks in advance.

acSaveNo is referring to design changes to the form, not to data. You
would have to cancel the BeforeUpdate event, and then Undo the entries, and
then close the form.

The whole "I want an explicit save" strategy really creates a lot of extra
work for you and irritations for the user. When I want to be extra careful
of accidental changes I lock all the controls on the form and then unlock
them when an "Edit" button is pressed. In that way you are removing the
need to ask "Are you sure you want to save that?" because they have already
indicated their intent ahead of time.
 
Ron said:
When I close a form any data entered into that form is
still saved in the table even though I have the code

DoCmd.Close , POProducts, acSaveNo

I have also tried a DoCmd.CancelEvent. When the exit
button is clicked I want the form to close and no new
record created in the table. What is going on and why is
a new record being created when I don't want it to?


That is standard behavior. The acSaveNo argument to the
Close method is telling Access to skip saving the DESIGN
changes to the form, it does not have anything to do with
data entered on the form.

The code behind your exit button would have to undo the data
changes before closing the form:

If Me.Dirty Then Me.Undo
DoCmd.Close acForm, POProducts, acSaveNo
 
Back
Top