Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert string containing control name to control name 2

Status
Not open for further replies.

SARProgrammer

Technical User
Oct 8, 2007
4
US
MS Access 2003

I have a form consisting of a matrix with 21 columns by 50 rows using a comboBox in a subform. On the main form I have 21 vertically aligned textboxes which will each contain the name of a trainee.

A query is used to determine the trainees in attendance on any given date. A recordset is created and an array is filled with the information needed for this particular subroutine (LName, FName).

All the name textboxes are named as follows:
nameTextBox_01
nameTextBox_02
nameTextBox_03
. . . . . . . . .
nameTextBox_20
nameTextBox_21


Although I am able to build the name of the control as a string:

Dim append as string

append = CStr(intRecord)
If Len(CStr(intRecord)) < 2 Then
append = "0" & CStr(intRecord)
End If
ctrl = "Me.nameTextBox_" & append

Resulting in “Me.nameTextBox_01” through “Me.nameTextBox_21”

How can I assign the values in the array to the name textboxes

Given TrainingAttendanceArray(1, intRecord) is Last Name
TrainingAttendanceArray(1, intRecord) is First Name

Currently I have the following lenghly case statement:

For intRecord = 0 To UBound(TrainingAttendanceArray, 2)
Select Case intRecord
Case 0
Me.NameTextBox_01 = TrainingAttendanceArray(1, intRecord) & ", " & TrainingAttendanceArray(2, intRecord)
Case 1
Me.NameTextBox_02 = TrainingAttendanceArray(1, intRecord) & ", " & TrainingAttendanceArray(2, intRecord)

. . .

Me.NameTextBox_20 = TrainingAttendanceArray(1, intRecord) & ", " & TrainingAttendanceArray(2, intRecord)
Case 20
Me.NameTextBox_21 = TrainingAttendanceArray(1, intRecord) & ", " & TrainingAttendanceArray(2, intRecord)
End Select
Next intRecord

Is there a simple way to convert the string of the control name “Me.NameTextBox_01” to the control name Me.NameTextBox_01 ?


 
Remou,
I am sure it is a typo knowing your exptertise, but you left the "Me." in the control name. Should be

ctrl = "nameTextBox_" & append
me(ctrl)

if you leave the me in the string it would resolve to an index of ctrl("me.nameTextBox_1")
 
Remou and MajP

Excellent!! Nice to wake up to a more elegant solution
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top