Expanding a variable or referencing a field within variable 
Author Message
 Expanding a variable or referencing a field within variable

How does one expand or refer to another variable within
another variable?  In dBase parlance it is called macro-
expansion.  Before run-time the variable being referenced
is not known.  Only at run-time does the varible become
identified and therefore must be expanded.  Here is a
trivial example; listing a group of fields within a
table.  There are nine fields within the table; week1,
week2. . .week9.  I want to refer to each one. I do not
want to "hard code" this but use a loop and refer to each
field:

For i_loop = 1 To 9
str_fieldname = "rst!week" & Trim(Str(i_loop))
Debug.Print str_fieldname
Next

I do NOT want the concatinated string to print.  I want
the CONTENTS of the field within the record set to print.  
Do I have to add extra quotes in the second or third line
of code? In dBase you use an operator "&" to expand the
varible i.e. Debug.Print &str_fieldname.  Moreover, what
do they call this in Access?

Thanks for the help,
Terry



Fri, 11 Jun 2004 23:23:34 GMT  
 Expanding a variable or referencing a field within variable
The Eval function is similar to dBase macro; check the
help. However, the loop you are looking for in VBA is:

 For i_loop = 1 to 9
   str_fieldname = rst("week" & Trim(Str(i_loop)))
   Debug.Print str_fieldname
 Next

--
'-------------------------------
' John Mishefske
'-------------------------------

Quote:

> How does one expand or refer to another variable within
> another variable?  In dBase parlance it is called macro-
> expansion.  Before run-time the variable being referenced
> is not known.  Only at run-time does the varible become
> identified and therefore must be expanded.  Here is a
> trivial example; listing a group of fields within a
> table.  There are nine fields within the table; week1,
> week2. . .week9.  I want to refer to each one. I do not
> want to "hard code" this but use a loop and refer to each
> field:

> For i_loop = 1 To 9
> str_fieldname = "rst!week" & Trim(Str(i_loop))
> Debug.Print str_fieldname
> Next

> I do NOT want the concatinated string to print.  I want
> the CONTENTS of the field within the record set to print.
> Do I have to add extra quotes in the second or third line
> of code? In dBase you use an operator "&" to expand the
> varible i.e. Debug.Print &str_fieldname.  Moreover, what
> do they call this in Access?

> Thanks for the help,
> Terry



Sat, 12 Jun 2004 00:04:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Variables within variables

2. referencing variables from within Sendkeys.

3. Referencing Global Variable from a variable

4. reference contents of variable as a variable...

5. referencing field names using a variable

6. Variable Reference to Field

7. Reference a Field Name with a variable?

8. Repost Code Example - using variables in field name references

9. Repost Code Example - using variables in field name references

10. Reference field obect with variable.

11. Referencing a Field through a Variable?

12. Referencing fields via variable

 

 
Powered by phpBB® Forum Software