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

Posted on 2012-12-27
Last Modified: 2012-12-27
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 ????
Question by:wlwebb
LVL 50

Accepted Solution

Rgonzo1971 earned 500 total points
ID: 38723096

False syntax n is a string you cannot add 1

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


Author Closing Comment

ID: 38723255
OOps.... Thanks

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question