Reference Subform Text box to From Text box

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

Guest

How do you reference a subform text box to a text box on a form in VB? I
know how to do it with the controls on a form, but how about a subform?

[form][subformname][ ? ]=[forms][formname][txtbox]
 
Try

Forms![FormName]![SubFromControlName].From![FieldName]

Or, if its in the same form
Me.[SubFromControlName].From![FieldName]
 
http://www.mvps.org/access/forms/frm0031.htm at "The Access Web" is a good
resource.

Note that when it talks about Subform1 or Subform2 in that reference, it's
referring to the name of the control on the main form that holds the
subform, not the name of the subform. Yes, if you drag a form onto another
form, the control will be named the same as the form that you dragged,
however if you select the Subform control from the toolbox and add it to the
form, you'll find that the control is named something like Child0.
 
Forms![FormName]![SubFromControlName].From![FieldName]
----------------------------------------^ should be Form![
Or, if its in the same form
Me.[SubFromControlName].From![FieldName]
--------------------------^ Form![


Just to save the confusion...<g>


Tim F
 
the subform is on the same form so I would try the second one. What is the
[SubFromControlName]? Is this the text box from the subform? If it's the
subform, when I tried using the subform name, I didn't get a "From" from the
auto select that VBA has after the period? Would [FieldName] be the form
text box? Sorry with all the questions, just feeling my way through. Thanks!
 
As Tim corrected my post, thanks Tim, I mispalled the form to from.
Try this

Me.[SubFromControlName].Form![FieldName]

SubFromControlName = the name of the sub form within the main form, the sub
form border in the main form

FieldName = The name of the field in the sub form you want to refer to from
the main form
 
I'm using this in the FormsControlName_Change, to make the Subform Control
equal to the form control. So I want to say:

Me.[SubFormControlName][SubFormTextBox]=[Forms]![FormsName]![FormsTextbox]

Can I say this in a Main Form Control?

When I try

Me.[SubFormControlName].Form![FieldName]

I get errors?
 
To assign a value to a text box in the mainform from a text box in a sub
form using VBA

Me.[FieldNameInMainFrom]=Me.[SubFormControlName].From![SubFormTextBox]

Or you can write in the control source of the text box that located on the
main form

=[SubFormControlName].Form![SubFormTextBox]
 
Back
Top