Access - VB for correct Syntax to use concanation of two variables when refering to a Textbox Control

wlwebb
wlwebb used Ask the Experts™
on
Hello All

I don't know all the terms well enough to know if my Title of this thread was worded correctly but here goes.....

I have a code where I am attempting to use two variables to allow it to do a series of things automatically.  My Textbox names all end with ## where ## are sequential numbered 01, 02, 03, 04 etc.....

Let's assume for this example my textboxes are Named txtbox01, txtbox02,txtbox03 etc..

Now then, I know I can write the code with something like this:

Me("txtbox" & n) = me("txtbox" & n+1)

Now I got the crazy thought, "hey what if I have to change the name and figure out my code"..... So I thought if using the me("xxxx"&n) worked so well, why can't I use something like me(s & n) = me(s & n+1)........where s & n are String variables.

Private sub xxxx
Dim n as String, s as String

s = Left(Me.ActiveControl.Name, (Len(Me.ActiveControl.Name) - 2))
n= Right(Me.ActiveControl.Name, 2)

Me(s & n) = Me(s & n+1)
End sub

Then just copy that coding to the afterupdate event of all the textboxes I want to use that for......

However, it doesn't work.........  is there a way to alter it to fix that ????
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Hi,

False syntax n is a string you cannot add 1

Me(s & n) = Me(s & Format(CInt(n) + 1, "00"))

Regards

Author

Commented:
OOps.... Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial