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

Controlling Subform fields, from the main forms code? 2

Status
Not open for further replies.

Varga

Technical User
Mar 28, 2003
43
CA
Hello,
I have a form that is based on one table and a subform based on a second table. The main form displays one record from the first table, and the subform displays all the related records from the second table.
I want to pass a value from the main form, to each record on the subform.
I can’t figure out how to control the subforms’ fields from the code in the main form. I don’t know how to refer to the subform.
(i.e. if “Me.[ ]” refers to the main form, what would refer to the subform?)

E.g:
For Each Rec in Subform
Let Me.[TransID] = Subform.[TransID] ?
Next

Is there an easy way to ‘talk to’ the fields in the subform from the main form?
How can I copy values from one table to multiple records in the second table?
Please let me know if you need further clarification,
Thanks
Blair
 
to refer to a subform control within the main form

[tt]Me!SubformName.Form!ControlName[/tt]


jul ^_^
"Computer Science is no more about computers than astronomy is about telescopes"
E. W. Dijkstra.
 
Me.name_of_the_control_countaining_the_subform.form.________

And after the last dot, you can do as if it was Me. on the subform.

E.G : if the subform control in the main form is subFrm and the control you want to reach in the subform is ctrl, then type :

Me.subFrm.form.ctrl
 
Thank you very much,
I can now refer to the subform and change it's values.
But unfortunatly my 'For Each' loop does not work.
It only changes the value of the field in the first record of the subform. Is there something wrong with my code.

Dim R
For Each R In Me.Pay_subform.Form
Let Me.Pay_subform.Form.[Pay User] = Me.[Cust User]
Next

Can you suggest a better way to loop through the records and change each one?

Thanks,
Blair
 
Nevermind, it works now.
I was missing the 'Go to next record' part.

Dim R
For Each R In Me.Pay_subform.Form
Let Me.Pay_subform.Form.[Pay User] = Me.[Cust User]
DoCmd.RunCommand acCmdRecordsGoToNext
Next

Once again thank you all for your help,
I think this site is great!
Thank you,
Blair :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top