How can I set a variable (Table_Select) equal to another string variable (Table_1)?
Example:
--------------------------------
Table_1 = "Winner"
For i = 1 to 3
Table_Select = "Table_" & i
--------------------------------
Table_Select should equal "Winner", not "Table_1" 8 7956
I think there is the VAL("Table_" & i).Name
or something like that
"John" <so*********@hotmail.com> wrote in message
news:90**************************@posting.google.c om... How can I set a variable (Table_Select) equal to another string variable (Table_1)?
Example: -------------------------------- Table_1 = "Winner"
For i = 1 to 3 Table_Select = "Table_" & i --------------------------------
Table_Select should equal "Winner", not "Table_1"
John wrote: How can I set a variable (Table_Select) equal to another string variable (Table_1)?
Example: -------------------------------- Table_1 = "Winner"
For i = 1 to 3 Table_Select = "Table_" & i --------------------------------
Table_Select should equal "Winner", not "Table_1"
Looks like you should consider using an array, otherwise I have no idea
what you're trying to accomplish.
Dim strTable(1 To 3) As String
Dim strTable_Select As String
Dim i As Long
strTable(1) = "Winner"
strTable(2) = "Runner Up"
strTable(3) = "Loser"
For i = 1 To 3
strTable_Select = strTable(i)
Debug.Print strTable_Select
Next
--
This sig left intentionally blank
tombsy wrote: I think there is the VAL("Table_" & i).Name
or something like that
No, Eval("Table_" & i) will do.
--
Bas Cost Budde, Holland http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
> No, Eval("Table_" & i) will do.
I'm not able to get this to work for me. Here's my code...at the
bottom is the logic I'm having trouble with:
'************************************************* *******************
Function UploadModel(Model_No As Integer)
Dim ModelPath As String
Dim TableName As String
Dim FileName As String
Dim RangeName As String
ModelPath = "P:\Forecast\"
'************************************************* *******************
'Model Definitions
'************************************************* *******************
'ProductA
Model_1 = "ProductA.xls"
Model_1_Range = "db_ProductA"
Table_1 = "xl_ProductA"
'ProductB
Model_2 = "ProductB.xls"
Model_2_Range = "db_ProductB"
Table_2 = "xl_ProductB"
'************************************************* *******************
'Upload Model
'************************************************* *******************
TableName = "Table_" & Model_No
FileName = model_path & "Model_" & Model_No
RangeName = "Model_" & Model_No & "_Range"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, & _
Eval("Table_" & Model_No), Eval("FileName"), True, Eval("RangeName")
End Function
John wrote: No, Eval("Table_" & i) will do. I'm not able to get this to work for me. Here's my code...at the bottom is the logic I'm having trouble with:
I was clearly mislead by your question.
TableName = "Table_" & Model_No FileName = model_path & "Model_" & Model_No RangeName = "Model_" & Model_No & "_Range"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, & _ Eval("Table_" & Model_No), Eval("FileName"), True, Eval("RangeName")
The DoCmd.TransferSpreadsheet needs *string* parameters. So instead of
having the Eval() expressions, you could use the variables assigned above:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, & _ TableName, FileName, True, RangeName
should do.
--
Bas Cost Budde, Holland http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Bas, thanks for the response. However, your suggestion of just using
the variables for the transferspreadsheet parameters is exactly my
problem. The variable would be a string...I need the "string" to be a
variable.
In other words...
"table_16" string needs to be table_16 variable, which is equal to a
string ("Some_table").
I mistakingly left out a line in the code before, but this is an
example:
'************************************************* **
TableName = "Table_" & Model_No
FileName = model_path & "Model_" & Model_No
RangeName = "Model_" & Model_No & "_Range"
Table_16 = "Some_Table"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, & _
Eval("Table_" & Model_No), Eval("FileName"), True, Eval("RangeName")
'************************************************* **
I think you're trying to use a variable name as something meaningful in and
of itself, which is not accepted practice.
In your first line, you set the value of TableName - presumably to
"Table_16" when you want that table. If that's what happens, Bas's code
does *exactly* what you want. If you're trying to do something other than
that, your really twisting the way variables work. There should be no need
to use the Eval function here, and no need to use the line Table_16 =
"Table_16".
Darryl Kerkeslager
"John" <so*********@hotmail.com> wrote: Bas, thanks for the response. However, your suggestion of just using the variables for the transferspreadsheet parameters is exactly my problem. The variable would be a string...I need the "string" to be a variable.
In other words... "table_16" string needs to be table_16 variable, which is equal to a string ("Some_table").
I mistakingly left out a line in the code before, but this is an example:
'************************************************* ** TableName = "Table_" & Model_No FileName = model_path & "Model_" & Model_No RangeName = "Model_" & Model_No & "_Range"
Table_16 = "Some_Table"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, & _ Eval("Table_" & Model_No), Eval("FileName"), True, Eval("RangeName") '************************************************* **
John wrote: Bas, thanks for the response. However, your suggestion of just using the variables for the transferspreadsheet parameters is exactly my problem. The variable would be a string...I need the "string" to be a variable.
Zah. That looks like a double pointer to me, and VBA is not well suited
for this.
What process is this question part of? If I can understand what goal
you're after, I may come with "an elegant solution" (the ph on my
keyboard doesn't work, I always have to type the g instead ;-) )
I see you are importing a spreadsheet, probably many of them.
--
Bas Cost Budde, Holland http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: PK9 |
last post by:
I have a string variable that holds the equivalent of a DateTime value. I
pulled this datetime from the database and I want to strip off the time
portion before displaying to the user.
I am...
|
by: al |
last post by:
char s = "This string literal";
or
char *s= "This string literal";
Both define a string literal. Both suppose to be read-only and not to be
modified according to Standard. And both have...
|
by: Nascimento |
last post by:
Hello,
How to I do to return a string as a result of a function.
I wrote the following function:
char prt_tralha(int num)
{
int i;
char tralha;
|
by: JohnR |
last post by:
Hi all,
I'm finally sick and tired of manually generating get/set properties for
each private variable in a class so I'm trying to create a macro to do it.
I'm stuck because I can't figure out...
|
by: HerbD |
last post by:
I have a loooong debugging session behind me! I finally found the reason for the problem and now would like to know, if it is a bug in my code or not standardconformant behavour of the compiler(s) or...
|
by: phpCodeHead |
last post by:
Code which should allow my constructor to accept arguments:
<?php
class Person {
function __construct($name)
{
$this->name = $name;
}
function getName()
|
by: cameljs18 |
last post by:
Converting a string variable into a string literal. How do I add the
@ character in front of the string?
I cannot add it when the string is created as it will affect other
parts of the program.
...
|
by: Hvid Hat |
last post by:
Hi
I want to highlight (make it bold) a word in some text I'm getting in XML
format. My plan was to replace the word with a bold (or span) tag with the
word within the tag. I've found the code...
|
by: mthread |
last post by:
Hi,
I am using a string variable in which I do lot of appending. The
only difficulty I am facing as of now is appending a integer/float
value to this variable. Although I can accomplish this task...
|
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...
|
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
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |