Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do Command: Save & Close From

Status
Not open for further replies.

Duplicity

Technical User
Feb 16, 2003
18
0
0
GB
I'm playing with Access (relatively new to it so bear with me) and I have a form with a "New record" button on it.

What I'd like is to include a command button to save the newly input information typed into the form fields and close the form, all at the same time.

I can set up the 'close form' bit (no rocket science in that one) but the combined command is a mystery to me.

Does anyone know of a way in which this can be achieved ?

I have Access 2000 and 2002 but the end result will be used exclusively with 2002, so...

My thank in advance to any suggestions.
 
It should save this automatically. But you can always force a save:
Code:
Private Sub cmdSaveClose_Click()
   DoCmd.RunCommand acCmdSaveRecord
Code:
' Then close..
Code:
   DoCmd.Close acForm, Me.Name
End Sub

Is that what you wanted?

Trevor
 
This code whould do it,

docmd.close acForm "YourForm",,acSaveYes
 
just want to clarify this more...
when you do a DoCmd.Close it saves the record.. so having both unless there's some really weird case, isn't necessary.
 
Natatbh -

This actually refers to saving changes made to the form, not the record. The acSaveYes means if there have been structual changes to the form, save them.

At least this has what I've been lead to believe, correct me if i'm wrong.

Trevor
 
Hi Duplicity,

Sorry I didn't read your question clearly. The way to do this i s the exactly how Trevahaha specified and he is also right about saving, I double checked it.
 
Thanks people and yes, the code worked perfectly.

It may seem simple to you but it had me bamboozled !

I'll learn, or so I keep telling myself...

Thanks once more for your kind help.

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top