How to stay in an add form for Save and New

B

Bill Murphy

I have a bound Add form for a table in my app, and currently have just a
Save and Close button which saves the new record and returns to the calling
form (called from a command button on another form in the app). I would
like to add another command button on the calling form named Save and New,
so that the user stays in the add form, all the text fields are cleared, and
a new record is started. An autonumber field on this add form is used to
assign the next unique key to a new record.

How can I accomplish this in code?

Bill
 
B

Bill Murphy

In my message below I meant to say, add a Save and New button in the Add
form, not the form that calls the Add form.

Bill
 
B

Bill Murphy

I found the solution to this. In the Save and Close button I'm closing the
form as follows:

DoCmd.Close acForm, Me.Name, acSaveYes

In the Save and New button I replaced the above code with:

DoCmd.Save acForm, Me.Name

DoCmd.GoToRecord , , acNewRec

This saves the current record to the table and leaves the user in the Add
form sitting on a new blank record.

Bill
 
M

Marshall Barton

Bill said:
I found the solution to this. In the Save and Close button I'm closing the
form as follows:

DoCmd.Close acForm, Me.Name, acSaveYes

In the Save and New button I replaced the above code with:

DoCmd.Save acForm, Me.Name

DoCmd.GoToRecord , , acNewRec

This saves the current record to the table and leaves the user in the Add
form sitting on a new blank record.

NO, it doesn't save the record. That saves the form's
design, it's the Close or GoToRecord that is saving the
record.

For bound forms, you can use:
Me.Dirty = False
to save the record, but unless the record fails a validation
test, it will save automatically when the Close or
GoToRecord runs.
 
B

Bill Murphy

Thanks Marsh,

Bill


Marshall Barton said:
NO, it doesn't save the record. That saves the form's
design, it's the Close or GoToRecord that is saving the
record.

For bound forms, you can use:
Me.Dirty = False
to save the record, but unless the record fails a validation
test, it will save automatically when the Close or
GoToRecord runs.
 
M

missinglinq via AccessMonster.com

The really important thing to understand here is that when DoCmd.Close is
used to close the form, if a new record fails a validation test, the record
will be dumped, and Access won't give you any warning of this! It simply
dumps the record, which is really kind of scary, since DoCmd.Close is the
code the Command Button Wizard uses! SO if you're using DoCmd.Close, it's a
good idea to always explicitly save the record first so that a warning will
be issued if validation fails.

If Me.Dirty Then
Me.Dirty = False
End If

DoCmd.Close

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top