Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

How force record to be saved before making an entry in a subform

I have a main form that opens with data entered in the fields from another form that is still open.   So there really is nothing to enter in the main form.  But I don't want the user to be able to enter anything in the sub-form until the main form record has been saved. This is because the ID of the main form record hasn't been established yet and the subform will be looking for that number.

How can I force the save of the main form record even is the user hasn't entered anything?

I did try DoCmd.RunCommand acCmdSaveRecord but it doesn't save it.
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SteveL13

ASKER

My onclick event of the suggested [Continue] command button is:

    Me.ForeignKey = Forms!frmPartsAndMaterialsHeader!txtPartsAndMatlsID
    DoCmd.RunCommand acCmdSaveRecord
    Me.subfrmPartsAndMaterialsDetails.Visible = True
    Me.subfrmPartsAndMaterialsDetails.Form!txtItemRef.SetFocus

Open in new window


But I can't compile.  Gets stuck on ForeignKey.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Simple enough.  I'm using this.
I guess I'm confused about what the question was.  I posted essentially the same code as Anders except I used the Dirty event of the subform so you wouldn't get the error by simply tabbing into the control.  I don't believe that errors should be raised by tabbing into a control.  In addition, I told you how to get the main record to save which seemed to be what your question was all about and even suggested hiding the subform until after the main form record was saved.
Pat,

You are correct.  I'm requesting attention so I can split the accepted solution.
Solution split.  Thank you to both of you.