2

So I have a sub form that creates a record (and record it), and then another sub form opens up for data entry...however can I still use an open arg to pass the value (ProjectID) between these sub forms.

I know exactly how to do this with forms, but trying this with subforms is a little different.

docmd.openform "FormExample",,,,,,Passingvalue

but can't do it like this:

 me.MyChild.SourceObject = "SecondSubForm",,,,,,PassingValue

so yeah the above might look ridiculous to those who know the right way, but I thought that this would illustrate exactly what I am trying to do.

So how can I pass the value? Do I even need to with subforms instead of forms? or would this variable hold my value even though it was created in the first sub form?

thanks justin

Justin
  • 4,461
  • 22
  • 87
  • 152

2 Answers2

1

I don't think there's any way to pass an OpenArg with SourceObject =

Can it work to assign the value to a control after you set the SourceObject?

Me.MyChild.SourceObject = "SecondSubForm"
Me.MyChild!SomeControl = PassingValue
HansUp
  • 95,961
  • 11
  • 77
  • 135
  • How would I do that with the parent added though...since I am setting this from another subform form's code..... i.e. Me.Parent.MyChild.txtPassingValue = PassingValue....tried adding the ! between MyChild and control, and got the same error. – Justin Nov 06 '10 at 16:52
  • That's different than `me.MyChild` in the question. I think what you're attempting here is to replace `Me` with a different subform, then try to assign a value to a control on the new subform from code on the old subform ... which is gone. If I got that right (?), I doubt it's possible. You sure do try some "interesting" stuff, Justin. :-) – HansUp Nov 06 '10 at 17:30
  • @Justin Consider having the Me form store PassingValue in a (hidden?) control on Me.Parent. Then the new Me subform could retrieve PassingValue during its On Load (which is triggered by the SourceObject assignment). Seems kludgey, but could work. – HansUp Nov 06 '10 at 18:11
  • I understand. So basically I used to use VBA SQL and such to navigate forms, saving data, and passing the Unique Unifying ID between those forms in hidden text boxes and such. Then I started using the OpenArg and DAO .save/.load/.update etc just to learn how. So I am guessing that if I use the whole subform within a subform scheme as I described, I am going to need to go back to the SELECT @@IDENTITY and pass to hidden text boxes kind of function, instead of this OpenArg thing huh? – Justin Nov 07 '10 at 02:24
  • i know there are probably a bunch of methods, just used those as examples....the main thing is the Open Arg global trick, versus the passing the Value from form to form and storing in hidden control trick. – Justin Nov 07 '10 at 02:25
  • 1
    I don't understand in a Master/Child form/subform why the LinkMaster/LinkChild properties don't take care of this. – David-W-Fenton Nov 07 '10 at 04:16
  • @David....so perhaps that is something I am simply unaware of. I will try it out and see. Do the forms have to be bound for this to work? the forms are unbound...Thanks! – Justin Nov 09 '10 at 02:51
1

Rather than using a Hidden control as an alternative you can add a public method or public property to the Child form and then call it.

Personally I prefer to use a method because typically mutating a property shouldn't have side-effects.

Here's an example.

The child form Called SomeChildForm will have this method

Public Sub SetSomeValue(ByVal somestring As String)

     Me.Text1.Text = somestring 'or probably something to do with the record source

End Sub

From the parent you do this

Dim frm As Form_SomeChildForm
Set frm = Me.SubFormControlName.Form
frm.SetSomeValue "x"
Conrad Frix
  • 51,984
  • 12
  • 96
  • 155