Save and exit

  • Thread starter Thread starter Guest
  • Start date Start date
Matt Dawson said:
Is it possible to create a save and exit button within VBA?

Save what exactly and exit what exactly?

To save the current record on the current form and then exit Access...

Me.Dirty = False
DoCmd.Quit
 
What do you mean by "create and save" the button? If you mean that you
are modifying a form using VBA, the answer is "Yes" - but it is not
quick and easy. Why not create an invisible button in form design, and
then make it visible as needed?

John
 
Sorry I didn't make myself clear.
I meant a save and exit command button to simply save the record and exit
the form.
 
Matt Dawson said:
Sorry I didn't make myself clear.
I meant a save and exit command button to simply save the record and exit
the form.

Records are automatically saved when you close a form. If you feel you really
need a button to close the form then you *should* actually save the record
explicitly in that code due to a bug in Access.

Me.Dirty = False
DoCmd.Close acForm, Me.Name

The Bug: If you close a form normally and there is an unsaved edit in the form
that does not comprise a legal record (required field missing for example) you
will get an error and warning message indicating that the dirty record cannot be
saved.

If you close the form with your own code, then that message is not shown. The
illegal record is discarded without the user being notified. By saving the
record first in your code you will be notified if the record cannot be saved for
some reason.
 
Back
Top