Loop thru controls in subform

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

Guest

Hi all, I have 20 controls(fieldnames) in a subform. I would like to change
their caption when the main form is open using VBA. All fieldnames begins
with txt1, txt2...txt20 Help to loop thru these controls and change its
caption. TIA.
 
You want to set the Caption of the label attached to each of these text
boxes?

Dim frm As Form
Dim strControlName As String
Dim i As Integer

Set frm = Me.[NameOfYourSubformControlHere].Form
For i = 1 to 20
strControlName = "txt" & i
frm(strControlName).Controls(0).Caption = strControlName
Next
 
Thank you! It works.

Allen Browne said:
You want to set the Caption of the label attached to each of these text
boxes?

Dim frm As Form
Dim strControlName As String
Dim i As Integer

Set frm = Me.[NameOfYourSubformControlHere].Form
For i = 1 to 20
strControlName = "txt" & i
frm(strControlName).Controls(0).Caption = strControlName
Next

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

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

Harry H said:
Hi all, I have 20 controls(fieldnames) in a subform. I would like to
change
their caption when the main form is open using VBA. All fieldnames begins
with txt1, txt2...txt20 Help to loop thru these controls and change its
caption. TIA.
 
Back
Top