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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I declare an array variable in Public

Status
Not open for further replies.

riskassure

Programmer
May 6, 2005
33
US
Hello,

I tried using the following code:

Public X(1 to 50) as string

But when I compiled it, I got an error message.

How can I fix this? Or is it even possible to create an array variable in public?

Thanks in advance

~~CW~~
 
Hmmm...it worked on mine...
Where are you declaring this variable? It needs to be in the public declarations section above all your subs and functions. It can't be inside of a sub or function.
 
Yes I declared at the very top, outside of any subs and functions, right below the

Option Compare Database

statement. The error message says:

Compile error:

Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules

~~CW~~
 
Though my initial thought and recommendation is to try to avoid publics, you will need to place it in a standard module, not a class module (i e en the VBE - Insert | Module...). Remember also that the code attached to a form or report, is actually a class module.

Roy-Vidar
 
I see... my code was attached to a form, so it wouldn't work. I have figured out a way around it now. Thanks!

~~CW~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top