View Full Version : Using a value or variable in a control name


welgonzales
05-19-2011, 09:43 PM
tables:
rsttblFlr (floor seating)
rsttblEmp (employee record)

==================
rsttblFlr.MoveFirst
For x = 1 To rsttblFlr.RecordCount

rsttblFlr.MoveFirst
Do While rsttblFlr.EOF = False
If xSeat = rsttblFlr("SeatNum").Value Then
SIPnum = rsttblFlr("SIPnum").Value

rsttblEmp.Index = "idxSIP"
rsttblEmp.MoveFirst
rsttblEmp.Seek "=", SIPnum

If rsttblEmp.NoMatch Then
MsgBox "Critical Error. Contact the Programmer!", vbCritical, "ERROR"
Exit Sub
Else
Empname = rsttblEmp("fname").Value
LABEL(x).Caption = Empname
End If
Exit Do
Else
rsttblFlr.MoveNext
End If
Loop
Next

I have a form that is like the layout of a small office. I've used the label control to represent seats or chairs. there are about more than 50 seats/labels in the form. The seats have names of the employees. Now I want to load the form and when loaded will fill out the label caption to the name of the employees.

how can I use a control name say a label and include an index with it so when the program loops it will load up the name of the employee base on the seat number stored on the table Flr?

basically, all i want to accomplish is use a label+a value say lblC1 where lbl + C1, lbl + C2....

thanks much and looking forward for any suggestions

pbaldy
05-19-2011, 10:02 PM
This type of thing:

Me("lbl" & VariableName)

where VariableName contained "C1".

welgonzales
05-19-2011, 10:14 PM
thanks for your quick reply!

let me just clarify if I got it right...

I can do this to loop and fill out all the label caption on my form??

me("lblC" & x).caption= EmployeeName

where x is the value on my for loop??

welgonzales
05-19-2011, 10:21 PM
Paul your a genius! it worked! thanks man

pbaldy
05-20-2011, 07:38 AM
Happy to help! Sorry I didn't answer your follow-up question, but that was my bedtime. :D