Variable in control name

echorley

Registered User.
Local time
Today, 17:08
Joined
Mar 11, 2003
Messages
131
I would like to use a variable in a control name in VBA. For example, each of the text boxes below will receive a value based on the results of a DLookup function:

Me.txtboxOverallAvgPassRate_2005
Me.txtboxOverallAvgPassRate_2006
Me.txtboxOverallAvgPassRate_2007

I would like to condense them into one line of code and use a loop to assign the values. Something like:

Me.txtboxOverallAvgPassRate_" & CurrentYear =

Obviously that does not work.

Thanks.
 
nearly right

to use a string, you need to address the forms controls collection
(same as you address the tabledefs collection)

so try

controls("txtboxOverallAvgPassRate_" & CurrentYear) =

or maybe

me.controls("txtboxOverallAvgPassRate_" & CurrentYear) =
 
Got it...
Me("OverallAvgPassRate_3_" & CurrentYear)
 

Users who are viewing this thread

Back
Top Bottom