Loop thru controls in subform

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.
 
A

Allen Browne

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
 
G

Guest

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.
 

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