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!

VBA Public variable declaration vs. Global declaration

Status
Not open for further replies.

Scott2S

Technical User
Oct 27, 2000
48
US
In Access 97, the public declaration of a variable replaces Access 2.0's global variable declaration. Apparently there are subtle differences between public and global variables in Access 97, does anyone know what the differences are? I can't find any information in the help or book about global variables. When I search for global in the help it comes up with public.


I have a converted database with many global declarations and am thinking about converting these to public.

(I posted this same thread over in the Access forum but decided it needed to go here instead)

Thanks in advance
 
Essentially, a global variable is available to all parts of your application, and dim'ing a variable as public also has this effect. However, there are restrictions in where you can dim things as global / public. IE you cannot declare a public variable in a private module (I think!!).

Generally speaking, you should try and keep your variables as local as possible and try to avoid global / public variables. There are of course situations where a global variable is ideal - such as username / userinitials / ...

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top