Trying to use variable as part of field name

ghh3rd

Registered User.
Local time
Today, 20:16
Joined
Feb 11, 2002
Messages
25
I am attempting to populate some text boxes in VBA by using a common beginning for the name, and the month (such as Oct) in a variable.

I have hard coded "Oct" into the code which works:
Me.txtAMER_Oct = rst.Fields("cnt")

I'm not sure how to incorporate the variable mth, tried unsucessfully:
Me.'txtAMER_' & mth = rst.Fields("cnt")
Me.txtAMER_ & mth = rst.Fields("cnt")
"Me.txtAMER_" & mth = rst.Fields("cnt")
etc, etc....

Any help will be appreciated.


Randy
 
Try:
Code:
Dim s as String

s="txtAmer" & mth
Me.Controls(s)=rst.Fields("cnt")
 
Thanks Banana - I was going bananas!

I had tried almost the same thing, but without "Controls" after Me.

Randy
 
Yes - it was what I was looking for. I had tried almost the same thing, but used Me. rather than Me.Controls.

Thanks for your help.

Randy
 

Users who are viewing this thread

Back
Top Bottom