Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do we create 2 dimensional array in Access? 2

Status
Not open for further replies.

Katya85S

Programmer
Jul 19, 2004
190
I've declared my 2-dimentional array as
Private arr(x, 12) as Variant
I need it to be accessible by different Subroutines on a form, so i have to declare it in the Declaration part (prior to all the subroutines) of the code page.
This throws an error every time i open the form, press any buttons, or turn to a Design mode.
The error is:
"The expression On Load you entered as the event property setting produced the following error: Variable not defined"
Perhaps it has something to do with "x" parameter of the array, or may be i'm doing it all wrong.
If doing the same declaration inside Subroutine, no errors are throwing. But then i won't be able to access this array's the values from different Sub.
Thank you all in advance.
 
What is the value of 'x' and when is it being set?

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
x is your problem.
For one it's undeclared.
It should also be initialized.

Public x As Integer
x = 8
 
Yes, i've tried that code. It changed nothing. The same error.
 
As far as I recall, you must ReDim:

[tt]Dim x As Integer
x = 8
Dim MyAry()
ReDim MyAry(x, 12)[/tt]
 
Public variables (accessible to all mudules),
should be declared in the declerations section,
of a STANDARD module.
AND, should be initialized prior to being called.
So, either on each Load event of every subform that calls it.
On the start up page of the application..

But, being public, make sure you reinitialize as needed.
One subform may change it's value but, wnen called again,
you may need a different value for a different subform.

I don't know your objective or purpose for this array,
so, maybe on each load event is the safest?
 
Thank you all you guys for help!
Zion7 and Remou, your advice works! Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top