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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Me.txtday & Trim(Stri+1)) & ".text = "hi"
mx
Me.txtday & Trim(Str(i+1)) & ".text = "hi"
mx
mx
How about:
Me.Controls("txtDay & i +1) = "Hi"
that works.
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>
<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.
dim i as integer
for i=1 to 31
me("txtday" & i)=<values>
next