Help! How do I pass a variable from a Form to the Subform?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Form with a Subform. The subform is invisible except in certain
situations when I need to make it show on my main form. When the subform
appears, I really need to take a field value off the main form and have it
displayed on the subform. I have assigned this field value to a variable.
But I can't seem to make it show up on my Subform.

I assign the variable value before I make the Subform visible. I have tried
the Subform Open and Load events on the Subform to assign my variable to an
unbound text box on my Subform, but nothing shows up.

What am I doing wrong?
 
Presumably the code that makes the subform visible is in the main form's
event, so you can code:
Me.[Sub1].Form![Text0] = Me.[Text1]
where:
- Sub1 represents the name of the subform control;
- Text0 represents the control in the subform to assign a value to;
- Text1 represents the control on the main form to read the value from.

Notes
a) You do not need to assign a value to the control named in the
LinkChildFields property of the subform control.

b) If you do assign a value it will replace whatever value was there in the
current record of the subform.
 
Thank you so much!!! It's working. I had tried something similar to this at
first, but it is quite obvious to me now that my syntax at the time was
incorrect and that's why it wasn't working.

Thanks for saving me. I have to use this logic a quite a few forms.

Thanks again!

Kathy


Allen Browne said:
Presumably the code that makes the subform visible is in the main form's
event, so you can code:
Me.[Sub1].Form![Text0] = Me.[Text1]
where:
- Sub1 represents the name of the subform control;
- Text0 represents the control in the subform to assign a value to;
- Text1 represents the control on the main form to read the value from.

Notes
a) You do not need to assign a value to the control named in the
LinkChildFields property of the subform control.

b) If you do assign a value it will replace whatever value was there in the
current record of the subform.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

KmhComputer said:
I have a Form with a Subform. The subform is invisible except in certain
situations when I need to make it show on my main form. When the subform
appears, I really need to take a field value off the main form and have it
displayed on the subform. I have assigned this field value to a variable.
But I can't seem to make it show up on my Subform.

I assign the variable value before I make the Subform visible. I have
tried
the Subform Open and Load events on the Subform to assign my variable to
an
unbound text box on my Subform, but nothing shows up.

What am I doing wrong?
 
Hi Allen.
Maybe You could advise me on some similar issue.

I have MainForm with two SubForms linked to the MainForm by ClientID
The Subform1 is datasheet-form with OrderID control as one of its
row-controls (each row is a different OrderID record-set).
The Subform2 is single-form based on query that contains OrderID (each page
gives more detailed/differently queried look of the relevant
OrderID-recordset from the Subform1 ). It is hidden (VisibleProperty is set
to NO)
I want to dblclick SubForm1' OrderID control and to 1) turn the SubForm2
visible while 2) showing the relevant OrderID page.
Is it fisible? How should I modify the following:

Private Sub OrderID_DblClick(Cancel As Integer)
Forms![MainForm]![SubForm2].Visible = True
Forms![MainForm].[SubForm2].Form![OrderID] = Me.[OrderID]
End Sub


Allen Browne said:
Presumably the code that makes the subform visible is in the main form's
event, so you can code:
Me.[Sub1].Form![Text0] = Me.[Text1]
where:
- Sub1 represents the name of the subform control;
- Text0 represents the control in the subform to assign a value to;
- Text1 represents the control on the main form to read the value from.

Notes
a) You do not need to assign a value to the control named in the
LinkChildFields property of the subform control.

b) If you do assign a value it will replace whatever value was there in the
current record of the subform.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

KmhComputer said:
I have a Form with a Subform. The subform is invisible except in certain
situations when I need to make it show on my main form. When the subform
appears, I really need to take a field value off the main form and have it
displayed on the subform. I have assigned this field value to a variable.
But I can't seem to make it show up on my Subform.

I assign the variable value before I make the Subform visible. I have
tried
the Subform Open and Load events on the Subform to assign my variable to
an
unbound text box on my Subform, but nothing shows up.

What am I doing wrong?
 
Back
Top