473,378 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Is there a way to reference a variable in VBA via a concatenation of the name?

The snippet of code below shows the long way to set a variable (lngRow) with
the value of a corresponding constant, based on a counter value. Is there a
way I could set lngRow without resorting to the Case statement by
introducing the value of J into the variable name like this: "Sess" & J &
"Row". Is there a way this can be achieved?

Select Case J
Case 1
lngRow = Sess1Row
Case 2
lngRow = Sess2Row
Case 3
lngRow = Sess3Row
Case 4
lngRow = Sess4Row
End Select
Nov 13 '05 #1
2 1743
Check the EVAL function -- it should provide what you need.

Larry Linson
Microsoft Access MVP

"Andrew Chanter" <he****@radsolutions.com.au> wrote in message
news:8i********************@news-server.bigpond.net.au...
The snippet of code below shows the long way to set a variable (lngRow) with the value of a corresponding constant, based on a counter value. Is there a way I could set lngRow without resorting to the Case statement by
introducing the value of J into the variable name like this: "Sess" & J &
"Row". Is there a way this can be achieved?

Select Case J
Case 1
lngRow = Sess1Row
Case 2
lngRow = Sess2Row
Case 3
lngRow = Sess3Row
Case 4
lngRow = Sess4Row
End Select

Nov 13 '05 #2
You could use an array of values:

Dim SessRow(1 to 4) as Long

SessRow(1)=9494
SessRow(2)=394894
SessRow(3)=3483
SessRow(4)=309390

lngRow= SessRow(J)

Or you could use the SessRow(J) value directly in code without assigning it
to lngRow.

Neil

"Andrew Chanter" <he****@radsolutions.com.au> wrote in message
news:8i********************@news-server.bigpond.net.au...
The snippet of code below shows the long way to set a variable (lngRow)
with
the value of a corresponding constant, based on a counter value. Is there
a
way I could set lngRow without resorting to the Case statement by
introducing the value of J into the variable name like this: "Sess" & J &
"Row". Is there a way this can be achieved?

Select Case J
Case 1
lngRow = Sess1Row
Case 2
lngRow = Sess2Row
Case 3
lngRow = Sess3Row
Case 4
lngRow = Sess4Row
End Select

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: axial | last post by:
Is there a way to define a variable by resolving other variables? I'm trying to build an "uber-variable" from user-selected components. I have control over the XML and can change it as needed. ...
3
by: Shabam | last post by:
I have a form page that accepts a text field variable. The problem is, I need to concatenate this text field variable with some other string. How can I get this done? So, suppose a user enters...
14
by: 97T | last post by:
Well this is still bugging me. I know there are other ways around this, but for a number of reasons I would like to be able to do this one simple thing. I have a form with a number of controls...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
2
by: Looch | last post by:
All, I'm trying to output but I can only get (brackets for clarity) when using the code below. How can I "break" into the query variable in the InsertName method to add the name parameter to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.