How to access global variable EXPLICITLY

V

vikram.singh

Hi,

i have declared one global varibale named VAR1 in form module and
another defined in sub proecdure with the same name (VAR1) in the same
form module . if i use VAR1 then local variable will be
accessed .......but if i wanna use the global variable explicitely in
the same procedure then how i we do that.........

Please let me know as i am new to VBA.
Thanks in advance.

Vikram
 
D

Douglas J. Steele

I don't believe you can. Change the name of one (or both) of the variables.

That's one of the reason why people use naming conventions such as prefixing
global variables with g, module-level variables with m and no prefix for
local variables.
 
B

Bill Mosca, MS Access MVP

You have to decide on a naming convention so that global variables are not
confused with those scoped to only one sub or function.Adopting a naming
convention will make coding much easier for you.

Also, I suggest using names more descriptive than VAR1. Names like
gvarLastName indicates a global variant variable for Last Names.
gstrLastName indicats a string variable.

If the "global" variable is really scoped to only a form o rreport, I use p
instead of g. The p stands for private indicating it is scoped to just the
object in which it is declared.
 

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