Save & New

  • Thread starter Thread starter Chuck Chopp
  • Start date Start date
C

Chuck Chopp

I have a form that is opened in "add" mode to add a new record into a
database. This has been working just fine w/o any problems. There is a
data validation routine that gets called when the form is closed and it
takes care of calculating some additional field values that get set in the
record before it is committed to the database.

Now, I would like to put a button on the form that does a "Save & New" such
that it runs the data validation subroutine, saves the record and then
clears the contents of the form and leaves it in a condition where it is
ready to have a new record's field values entered into it again. I would
like to do this w/o having to close the form and re-open the form again.

I tried the following in an event procedure for a button on the form:

Me.Recordset.Update
Me.Recordset.AddNew

Unfortunately, this closes the form [saves the data, too] and does not allow
me to keep the form open for additional data entry tasks.

How do I implement a "Save & New" type of button on my form?


TIA,

Chuck
--
Chuck Chopp

ChuckChopp (at) rtfmcsi (dot) com http://www.rtfmcsi.com

RTFM Consulting Services Inc. 864 801 2795 voice & voicemail
103 Autumn Hill Road 864 801 2774 fax
Greer, SC 29651

Do not send me unsolicited commercial email.
 
Move your validation code into the BeforeUpdate event of the form. That way
it will always fire, regardless of what triggered the save.

There is a command button wizard that you can then use to move to a new
record. Essentially all it needs is:

If Me.Dirty Then 'Save if necessary.
Me.Dirty = False
End If
If Me.NewRecord Then
Beep
Else
RunCommand acRecordsGotoNew
End If
 
Allen said:
Move your validation code into the BeforeUpdate event of the form. That way
it will always fire, regardless of what triggered the save.

There is a command button wizard that you can then use to move to a new
record. Essentially all it needs is:

If Me.Dirty Then 'Save if necessary.
Me.Dirty = False
End If
If Me.NewRecord Then
Beep
Else
RunCommand acRecordsGotoNew
End If


Thanks. That appears to be working almost perfectly.

One new tiny complication has been introduced. Now that there's the
possibility of wanting to close the form after having clicked the "Save &
New" button but not having entered a final set of data into the fields on
the form, I get a warning that the record cannot be saved since a mandatory
field is missing a value.

If I detect that a mandatory field is missing in the before update event,
what can I do to silently cancel/abort the record add/update and allow the
form to close w/o the user being prompted?


--
Chuck Chopp

ChuckChopp (at) rtfmcsi (dot) com http://www.rtfmcsi.com

RTFM Consulting Services Inc. 864 801 2795 voice & voicemail
103 Autumn Hill Road 864 801 2774 fax
Greer, SC 29651

Do not send me unsolicited commercial email.
 
I think I got this one on m own....

In my before update handler, if I detect an "empty" form, I use "Me.Undo"
and that seems to silently cancel the update/add record attempt that was
choking on the field that had an empty value in the form but which was
marked as mandatory in the database.


--
Chuck Chopp

ChuckChopp (at) rtfmcsi (dot) com http://www.rtfmcsi.com

RTFM Consulting Services Inc. 864 801 2795 voice & voicemail
103 Autumn Hill Road 864 801 2774 fax
Greer, SC 29651

Do not send me unsolicited commercial email.
 
Back
Top