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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3 Subforms One Save Button

Status
Not open for further replies.

jkelly295

MIS
Aug 14, 2001
15
US
I have three sub forms incorporated into one main form. I want to put a save button on one of the subforms that saves the data in that form plus saves it in the others as well. Then Make all three go to a new record.

The problem I am having is how to reference the DoCmd action for the other forms from the save button Sub on the last sub form

I have...
[Forms]![Master]![New2].[Form].DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

For New
[Forms]![Master]![New2].[Form].DoCmd.GoToRecord , , acNewRec

Any Ideas....
 
2 things. First your syntax for the DoCmd object is incorrect. The DoCmd is not a method of your subform so therefore would not be ---> <subform>.DoCmd

You will notice that most DoCmd methods have an argument for which control you are working with. The correct way to handle this would have been.

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

and

DoCmd.GoToRecord , , acNewRec

The second point is that Access automatically saves data everytime you move focus between controls. Is it really neccesary to make a acSaveRecord call? You may want to experiment and find out if its really neccesary.

But the first point is very important to remember when using the DoCmd object. DoCmd is THE object not the method. VB syntax is...

<object>.<method> <arguments>

Let me know if that helps you at all.
 
me.refresh
me.subform1.form.refresh
me.subform2.form.refresh

Aivars
 
Ok the save is not really necessary but I need to create a new record for all three subforms with one click.

I already have the code as you mentioned for the subform that the button is on. The problem is that I also need that button to call the

DoCmd.GoToRecord , , acNewRec

action for all three subforms. Like

DoCmd.GoToRecord , , acNewRec ---gives new rec here
(?form2???)DoCmd.GoToRecord , , acNewRec --new rec on form2
(?form3???)DoCmd.GoToRecord , , acNewRec --new rec on form3





In other words I want one button to start all three subforms on a new record.

Thanks A lot


 
I figured it out myself finally....

Here is the solution

Private Sub SaveChanges_Click()
On Error GoTo Err_SaveChanges_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl &quot;[New2]&quot;
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl &quot;[subSalesReps]&quot;
DoCmd.GoToRecord , , acNewRec


Exit_SaveChanges_Click:

Exit Sub

Err_SaveChanges_Click:
MsgBox Err.Description
Resume Exit_SaveChanges_Click

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top