Cannot Get Cancel Button to Work correctly

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

Guest

Form A is bound to Table A
Form B is bound to Table B
I have a button on Form A whose Click event opens Form B and gives Form B
focus. Form B has a Cancel button that is supposed to prevent the new record
from being added to Table B. In the Cancel button's Click event, I am using
the code:

DoCmd.Close acForm, "Form B", acSaveNo

but the record gets saved to Table B anyway. What am I doing wrong?
 
Lowell said:
Form A is bound to Table A
Form B is bound to Table B
I have a button on Form A whose Click event opens Form B and gives Form B
focus. Form B has a Cancel button that is supposed to prevent the new
record
from being added to Table B. In the Cancel button's Click event, I am
using
the code:

DoCmd.Close acForm, "Form B", acSaveNo

but the record gets saved to Table B anyway. What am I doing wrong?

DoCmd.Close acForm, "Form B", acSaveNo

will prevent changes made to the _form_ being saved.

To prevent changes to the _record_ being saved, use:

Me.Undo
DoCmd.Close acForm, "Form B"

(Incidentally, it is better practice to use Me.Name rather than a string
literal, ie "Form B", when the code is running in the form's module) :

Me.Undo
DoCmd.Close acForm, Me.Name
 
Thanks, Stuart.

I looked through four programming manuals and none explained how to do this.
Visual basic help wasnt helpful either. Thanks for the help and the tips.

Lowell
 
Back
Top