Question : Save Record Only On Save

This is a pretty fundamental question about how Access forms work.  It seems that if a form is opened in Add mode, provided the data meets all the requirements the record is saved with no further ado.  This is not the behavior I want on a particular form, however.  I want the record saved only if the user clicks the SAVE button.  I feel like If Me.Dirty Then Undo in the form's _Close event should solve this, but it doesn't.  Records get added every time I open the form.  I should add that the form fills itself out based on certain parameters at load time, such as today's date.  Enough information is supplied by this autopopulation to constitute a complete record, in fact.  I am actually altering the controls' .Value properties to do this.  Is that my problem?  I think there's a .DefaultValue property for some controls, or something like that.  Is that what I should be using?

Mike

Answer : Save Record Only On Save

I figured out that my "If Me.Dirty then Me.Undo" idea was sound, I just had it in the wrong place.  The controls are disabled, as per HartCraft's suggestion, so you have to click the Close button to close the form.  But in the Close Click handler, I use the code DoCmd.Close acForm, Me.Name to close the form, and had Me.Undo in the form's Close handler.  By the time the form's Close handler fires, the record is already saved and the form is no longer dirty.  By moving the If Me.Dirty code to the close button's click handler it solved the problem.

Mike



Random Solutions  
 
programming4us programming4us