Variable variables?

G

Guest

I am have defined a 3x3 table in a form and the user can place a value in
each cell. I need to copy the values from the 9 table cells into global
variables (for later use).
The "naming convention" I used for each cell of the table is CELL_CxRz
(where Cx is a Column number and Rz is a Row number). The convention I use
for the global variables is GBL_CxRz.

I can build variables using two FOR loops for the column and row numbers.
DIM CELLNAME, GBLNAME as STRING
FOR ROW=1 to 3
FOR COL=1 to 3
CELLNAME = "CELL_C" & COL & "R" & ROW
GBLNAME = "GBL_C" & COL & "R" & ROW
' *** HERE IS THE PROBLEM!
' *** I WANT TO DO SOMETHING LIKE:
(GBLNAME) = ME(CELLNAME)
'*** The ME(CELLNAME) works fine
'*** I do not have the correct syntax for storing the contents of
ME(CELLNAME) into the variable contained within GBLNAME
NEXT COL
NEX ROW

Can anyone help?

Thanks, in advance
Rich
 
G

Guest

3$5bv%*&U$^$^@H^%^N^$^THIS IS NOT EXCEL!!!!!!!!!!!!!!!!!!

Now that I have that out of my system, lets solve your problem.
Seriously, use other names. There are no cells in Access. On a form there
are controls. In a table there are fields.

I understand what you are trying to do, and you have the basic logic in
place. Rather than use 9 variables, use 1 array dimmed the same 3x3. The
same For Next logic will work. Since you are using For 1 to 3, you will need
to have the Option Base 1 statement in your modules so the array will start
at 1. Unless you use the above statement, they start at 0. Then dim your
array:

Public varMyArray(3, 3) as Variant

Then in your code, to assign the values it will be:
varMyArray(COL, ROW)

Simple as that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top