BeforeUpdate Code upon Closing Form

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

Guest

I have code on BeforeUpdate event which basically checks whether users want
to save their changes and some fields validation.
The problem starts when user closes the form and decided to save their
changes. It's fine if their changes are corrects but if there are errors in
their changes then they don't have opportunity to correct them - the form
just closes.
Anyway to get around this?

TIA,
Sugih
 
Sounds like you are describing a basic flaw in the way the Close
action/method operates.

If you close a form via a command button, it *silently* loses what the user
entered. The solution is to explicitly save the record before issueing the
Close, e.g.:
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.name
Use error handling: if the record cannot be saved, the code fails when it
tries to set Dirty to False, and so the close is never executed.

More information:
Losing data when you close a form
at:
http://members.iinet.net.au/~allenbrowne/bug-01.html
 
Thanks Allen, I will try this aproach, disable the form's close button and
put a code to save the record on the command close event.
Cheers,
Sugih
 
The form's Close event is too late: the record is already saved (or
discarded) by then.
 
Back
Top