Problem with command button CANCEL Property.

S

Steve S

I posted a quewstion yesterday (see Close form without saving data ) but
thought I had the solution before anybody responded. According to Access
HELP if you set the CANCEL property of a button that is the CLOSE button any
changed data in the current record is discarded and not saved.

I set the property to yes and have a button that executes the doCmd.Close
command. If a user has changed either the combobox or the text field that is
bound to the data record the change is saved nomatter what.

Help
 
R

Rick Brandt

Steve said:
I posted a quewstion yesterday (see Close form without saving data )
but thought I had the solution before anybody responded. According
to Access HELP if you set the CANCEL property of a button that is the
CLOSE button any changed data in the current record is discarded and
not saved.

Then you misinterpretted what you read. That is incorrect. You have to set
Cancel = True in the BeforeUpdate event AND issue an Undo on the form.
 
S

Steve S

Thanks rick. Not sure I know wnat you mean by "issue an UNDO on the form".
And do I have to do a test for updates wo I won't get the error message about
UNDO not available at this time.

Steve
 
R

Rick Brandt

Steve said:
Thanks rick. Not sure I know wnat you mean by "issue an UNDO on the
form". And do I have to do a test for updates wo I won't get the
error message about UNDO not available at this time.

Normally cancelling the update just stops the save. The Undo is what reverts
all entries back to what they were before the edit started (or clears them on a
new record). Without the Undo the form is still dirty and the update events
will just fire again.

BeforeUpdate only fires when changes have happened so there is no need to test
for that.
 
S

Steve S

in the BeforeUpdate code I put:

Cancel = True
Me.Undo

that worked

thanks much for the very good explaination.

Steve
 
Top