Assigning dynamic contol name properties

M

Mymind

I have a form that contains twenty controls for # of hours, Sum of hours, and
hours_label. (example: A1_Hours, A2_Hours....,A20_Hours and A1_HoursSum,
A2_HoursSum....,A20HoursSum and
A1_Hours_Label,A2_Hours_Label....A20_Hours_Label )

I have created a private sub that loops through a datasource that contains
up to 20 label captions. Based upon the number of captions (x) I would like
to set the associated control properies:

Example:
x=1
Do While Not rs.EOF 'Loop through all records in dataset
'Read in initial AC_CATEGORY_NAME
Act_Cat = rs(1)
'Set field label, and visability parameters
BHE_Ax_HOURS.Visible = True
BHE_Ax_Sum.Visible = True
BHE_Ax_HOURS_Label.Visible = True
BHE_Ax_HOURS_Label.Caption = Acct_cat
'Increment counter and Step to next record
x = x + 1
rs.MoveNext
Loop

How do I dynamically name the control? I tried "BHE_A"&x&"_HOURS" but this
does not work
 
G

George Nicholson

ohhhhh, soooo close:

frm.Controls("BHE_A"& x &"_HOURS")

(where frm is the Form you are working with. You could substitute Me if your
code is in that Form's module)

HTH,
 

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