Cannot Get Cancel Button to Work correctly

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?
 
S

Stuart McCall

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
 
G

Guest

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
 

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