Link to home
Start Free TrialLog in
Avatar of advlegals
advlegals

asked on

Access VBA - Dynamically Reference A Text Box Control In Code

I have a group of 31 text box controls and I need to be able to reference them directly i.e.

The control naming convention is: txtDay1, txtDay2, txtDay3 ... txtDay31.

I need to be able to assign values to these dynamically and it would seem logical to me to use:

Me.txtday" & i+1 & ".text = "hi"

...although obviously this does not work.

Is there any way that I can concatinate an integer value to my text box object txtday in code?

Thanks for anything.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


dim i as integer

for i=1 to 31
   me("txtday" & i)=<values>

next
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Me.txtday & Trim(Stri+1)) & ".text = "hi"

mx
Me.txtday & Trim(Str(i+1)) & ".text = "hi"

mx
How about:

 Me.Controls("txtDay & i +1) = "Hi"

that works.
Sorry, Miriam, I should have refreshed.
np, Ray :-)

<OT>
Are you receiving email notifs?  Mine (hotmail) don't seem to be working.
</OT>
Working fine for me - using Outlook - Firefox as the browser.