Text box and label question

Hi EE

I have a form with 31 text box's and 31 labels. I need to name
Labels as l1 l2 l3 etc
Text box as T1 T2 etc

From memory without going to each box and naming T1 etc there is a process called indexing
but it alludes me as to how it's done. Any help appreciated

chestera
chesteraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<From memory without going to each box and naming T1 etc there is a process called indexing
but it alludes me as to how it's done. Any help appreciated>>

 Hum...Access names controls like that when you create them, but there's nothing that will rename controls like that once their created.

 You could do it in code, but there's nothing built-in that you can use.

Jim.
0
Jeffrey CoachmanMIS LiasonCommented:
Just curious, ...
...why not give them more descriptive names...?
0
Gustav BrockCIOCommented:
You can do something like this:

Dim ctl As Control
Dim intControl As Integer
For Each ctl in Me.Controls
    If ctl.ControlType = acTextBox Then
        ctl.Name = "T" & CStr(intControl)
        intControl = intControl + 1
    End If
Next

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<Just curious, ...
...why not give them more descriptive names...? >>

 Probably trying to simulate a control array and will be looping through like this:

 Form("Item" & intK)

Jim.
0
chesteraAuthor Commented:
boag200

I have created a monthly scheduler with 31 text box's and 31 labels (Days of the month)
L1 L2 for lables
T1 T2 for text box's
is easier than typing LabelDay1 and TextboxDay1
Label will contain day of the month and the text box's will contain events. I have it working from a form but the user now won'ts me to create a report so They can print out the everntss for any given month.

Alan
0
chesteraAuthor Commented:
Jdettman

Hi Jim

I have created a monthly scheduler with 31 text box's and 31 labels (Days of the month)
L1 L2 for lables
T1 T2 for text box's
is easier than typing LabelDay1 and TextboxDay1
Label will contain day of the month and the text box's will contain events. I have it working from a form but the user now won'ts me to create a report so They can print out the everntss for any given month.

Alan
0
chesteraAuthor Commented:
cactus_data

Thank Gustav I will give it a try

Alan
0
chesteraAuthor Commented:
cactus_data

Tried your code and it stated can only work in design view. Not sure how to implement that in design view. This is no big deal I can name each box and label just thought there might be a quicker way. I remember doing something similar many years ago but might be getting confused I used to work in "C"

Alan
0
chesteraAuthor Commented:
jdettman

What happens if no resolution to the question. As I have said to Gustav I will just name each box and label individually just thought there might be a quicker way (A lazy way out)

Alan
0
Jeffrey CoachmanMIS LiasonCommented:
<No Points wanted>

<Tried your code and it stated can only work in design view. Not sure how to implement that in design view.>

Create another form to run the code, Name this form: frmRenameControls
Put a button on this new form to open the target form that you want to modify.
The code on this button will be something like this:


Dim ctl As Control
Dim intControl As Integer

DoCmd.OpenForm "YourTargetFormName", acDesign
Forms!YourTargetFormName.SetFocus

'Rename the textboxes
For Each ctl In Forms!YourTargetFormName.Controls
    If ctl.ControlType = acTextBox Then
        ctl.Name = "T" & CStr(intControl)
        intControl = intControl + 1
    End If
Next

'reset the counter
intControl = 0

'Rename the labels
For Each ctl In Forms!YourTargetFormName.Controls
    If ctl.ControlType = acLabel Then
        ctl.Name = "L" & CStr(intControl)
        intControl = intControl + 1
    End If
Next
DoCmd.Close acForm, "YourTargetFormName", acSaveYes


Note that this will not change the label *Caption* (that appears on the form, to the user), it will only change the the name

Again, no points wanted as all I am doing here is helping out...
Code is Gustav's, ...so please give him all the points...

JeffCoachman
0
chesteraAuthor Commented:
jeffcoachman

Many thanks Jeff. I will award the points to Gustav

Alan
0
chesteraAuthor Commented:
cactus_data

Thank you for your help. Jeff Coachman has addded to your code and he doesn't want any points.

Alan
0
chesteraAuthor Commented:
cactus_data

Again thank you Gustav

Alan
0
Gustav BrockCIOCommented:
You are welcome.
And thanks Jeff, no reason to be so modest.

/gustav
0
Jeffrey CoachmanMIS LiasonCommented:
That's what friends are for...
;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.