what is Syntax to reference subform field

J

Joe

I am trying to reference a field that is part of a subform from the main
form.

For example, I want to change the background color of a field on a subform
based on a command on the main form. So I want to do something like this:

MainForm!Subform_name.field_name.backcolor - 255

But I can't get the syntax right.
 
D

Douglas J. Steele

Forms![NameOfMainForm]![NameOfSubformControlOnMainForm].Form![NameOfControlOnSubform].BackColor
= 255

Note that depending on how you added the subform, the name of the subform
control on the parent form may be different than the name of the form being
used as a subform.

See http://www.mvps.org/access/forms/frm0031.htm at "The Access Web" for
more deatils.
 
J

John W. Vinson

I am trying to reference a field that is part of a subform from the main
form.

For example, I want to change the background color of a field on a subform
based on a command on the main form. So I want to do something like this:

MainForm!Subform_name.field_name.backcolor - 255

But I can't get the syntax right.

Note that the subform name that you need is the Name property *of the Subform
control*, the box containing the subform. This will often be the same as the
name of the Form object contained within that control - but not necessarily.

The correct syntax would be

MainForm!Subform_name.Form!control_name.backcolor - 255

Bear in mind that forms don't have fields, they have controls; again, the name
of a textbox may be the same or different than the name of that control's
Control Source field.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top