Cancel New Record with a button

  • Thread starter Thread starter Chris B.
  • Start date Start date
C

Chris B.

I am trying to put a cancel button on an input form that
will allow the user to cancel the add process in the
middle of adding data.

Thanks
 
Chris B. said:
I am trying to put a cancel button on an input form that
will allow the user to cancel the add process in the
middle of adding data.

How about:

Private Sub cmdCancel_Click()

Me.Undo

' If you want to close the form, uncomment this line:
' DoCmd.Close acForm, Me.Name

End Sub
 
Does Not work! This action is taking place in a subform
with a pull down menu. For some reason, after I make a
selection, I can not cancel out even with the undo...
 
Chris B. said:
Does Not work! This action is taking place in a subform
with a pull down menu. For some reason, after I make a
selection, I can not cancel out even with the undo...

Where is the command button? If it's on the main form, not on the
subform, then the subform record will already have been saved by Access
as a matter of course when the focus moves from the subform back to the
button on the main form. There is *no* way of stopping this automatic
save, so if this is what's going on you have to either put the button on
the subform instead of the main form or else do some elaborate
programming to allow you to roll back the changes to the subform's
recordsource table after they've been saved.

If, on the other hand, the button *is* on the subform, and is clicked
before the focus has been moved back to the main form or the subform's
record has otherwise been saved, then it ought to work and you'll have
to tell me more about your setup if I'm to figure out why it doesn't.
 
The master form has 20 fields and at the bottom of the
form is an add button. When selected, a sub form pops up
with only three fields (required to generate a tracking
number) Two of the fields are default values (zero, and
date()) the third field is a pull down menu and the
cancel button is on this subform. If I the subform is not
dirty, the cancel button just closes the subform (works),
however, if a value in the first field has been selected
and then I click cancel, the form closes but a new record
appears in the master table. Hope this clears it up.
 
Chris B. said:
The master form has 20 fields and at the bottom of the
form is an add button. When selected, a sub form pops up
with only three fields (required to generate a tracking
number) Two of the fields are default values (zero, and
date()) the third field is a pull down menu and the
cancel button is on this subform. If I the subform is not
dirty, the cancel button just closes the subform (works),
however, if a value in the first field has been selected
and then I click cancel, the form closes but a new record
appears in the master table. Hope this clears it up.

Hmm. If your subform "pops up", it probably isn't a true subform at
all. Is it opened by calling DoCmd.OpenForm in the code behind the "add
button" on the master form?

But if it's not really a subform, I'd expect the code I posted to work.
Please post the complete code from the popup form's code module.
 
Back
Top