We help IT Professionals succeed at work.

Parent and subform 2

pdvsa asked

In the below code I am trying to reference the Parent and subform.  The error I get is object required.  [Buy_CP] is located in parent frmprojectDetails and subform: subfrmProjects_Extended_List.

DoCmd.OpenForm "frmLetterOfCredit", acFormDS, , , , , OpenArgs:=frmprojectDetails.subfrmProjects_Extended_List.Buy_CP

Thank you
Watch Question

pdvsaProject finance



I hope I have used the correct language.  I am trying to open frmLetterOfCredit based on the OpenArgs criteria and Buy_CP is on the parent subform as detailed above.  If it is unclear please let me know what I have missed. 

Software & Systems Engineer
DoCmd.OpenForm "frmLetterOfCredit", acFormDS, , , , , Form_subfrmProjects_Extended_List.Buy_CP

Open in new window

This should the job
It only requires that
subfrmProjects_Extended_List has code behind (easy if you don't know...just open subfrmProjects_Extended_List in Design View ...hit the "View Code" to enter VBE and then just close...it ...nothing more
Most Valuable Expert 2015
Distinguished Expert 2018

You probably need the extended syntax:

DoCmd.OpenForm "frmLetterOfCredit", acFormDS, , , , , frmprojectDetails!subfrmProjects_Extended_List.Form!Buy_CP.Value

Note please, that subfrmProjects_Extended_List must be the name of the subform control.

Mark EdwardsChief Technology Officer
OK.  Let's see if we got this straight.....  Follow me as I stress the difference between a subform control and a form used as a subform.

From your initial description, you have a parent form (which is NOT used as subform for another form) named "frmProjectDetails".
This form has a subform control (name unknown) which has as its .SourceObject a form named "subfrmProjects_Extended_List".  (If that is not correct, please let us know)
Both the subform "subfrmProjects_Extended_List" and its parent form "frmProjectDetails" have a control on them named "Buy_CP" as indicated by your statement "[Buy_CP] is located in parent frmprojectDetails and subform: subfrmProjects_Extended_List."

Now you have a DoCmd where you want to open a form (as a stand-alone form - not as a subform) named "frmLetterOfCredit" as a datasheet that is having an OpenArgs value passed to it.

The format for referencing controls on a subform that is on a parent form is:

Based on this format, the reference from Gustav's code specifies the following:
frmprojectDetails is the parent form (which is NOT a subform of another form)
subfrmProjects_Extended_List is the name of the subform control holding the subform (not the name of the form that is acting as a subform).
Form is the reference to the form that is in the subform control (you don't need the name of the subform).
Buy_CP is the name of the control on the subform holding the value we want.

Based on this, I think Gustav's code should do the trick.  That is, if we have all the names and positions in the chain correct.
pdvsaProject finance



Gustav, thank you.  It gave me an Object Required.  


that did it.  Thank you very much!

Mark:  thanks for the explanation.  

thank you for your patience.  I am far from expert. No coding experience.