[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 943
  • Last Modified:

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.
0
advlegals
Asked:
advlegals
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Rey Obrero (Capricorn1)Commented:

dim i as integer

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

next
0
 
mbizupCommented:
Try this:

Me.Controls("txtDay" &  i+1) = "Hello"
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:

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

mx
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Me.txtday & Trim(Str(i+1)) & ".text = "hi"

mx
0
 
GRayLCommented:
How about:

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

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

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now