Subform - Change Caption?

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

Guest

I have searched this board and have found similar questions and answers, but
none of the solutions seem to work for me. Can you help?

Details:
I have two forms: 2-1_modifyBillable and 2-2_sub. "2-2_sub" is a sub form
embedded in the main form "2-1_modifyBillable." I am trying to modify
captions in the subform based on information inserted into the master form.
Problem is, I cannot set the focus to the subform. My code looks something
like this:

' assign variables from sql output
cId = strFound1
m1_label = "test"
m2_label = "test2"


' set focus
Me.subfrm.SetFocus
' note: subfrm is the control name of 2-2_sub


' assign lables
Me.m1.Caption = m1_label
Me.m2.Caption = m2_label

Thanks in advance!
 
The proper syntax form, assuming the code is in the main form module is:

Me.2-2_sub.Form.Caption = "Test"

Your post says captions (plural). There is only one caption for a form.
 
Thanks for the post Klatuu!

I am trying to change the captions for several controls within the subform
(i.e. form fields). Therefore, the syntax you supplied will not work (unless
I misunderstand). The syntax I am using for control captions does work
(Me.m1.Caption = m1_label), the problem is that right now I can only change
control captions on the main form. Any other ideas?
 
You are not catching the total picture here.

First, it is important to note that the subform you are referring to is not
a form, but a control on the main form. Subform Controls do not have a
Caption property. One of the subform control's properties is the Source
Object. The Source Object is the form contained in the subform control.
Therefore, when you are referencing anything on a subform, you have to
include the reference to the form. For example, to reference the Caption
property of the subform control's form, the syntax is:

Forms!MainFormName!SubFormControlName.Form.Caption

To change the caption of a control on the subform control's form is:

Forms!MainFormName!SubFormControlName.Form!ControlName.Caption
 
Back
Top