Public variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I realize some programmers frown on using Public variables but some times you
just have to. My question is how and what is the best way to access them??
It seems sometimes I need to write a quick function to access their value and
other times I can access them directly. Could someone please 'splain this to
me and maybe give me a rule-of-thumb to go by. I've looked it up in several
books and nobody seems to address it very well, besides the defining part. I
don't need a lesson on how to create them, just a little guidance on the
implimentation of them. Thanx...
 
Gil said:
I realize some programmers frown on using Public variables but some
times you just have to. My question is how and what is the best way
to access them?? It seems sometimes I need to write a quick function
to access their value and other times I can access them directly.
Could someone please 'splain this to me and maybe give me a
rule-of-thumb to go by. I've looked it up in several books and
nobody seems to address it very well, besides the defining part. I
don't need a lesson on how to create them, just a little guidance on
the implimentation of them. Thanx...

In VBA code you should be able to access them directly. In a query or a Control
expression you have to use a function that returns the variable value.
 
As a general rule, I don't use VBA Public Variables. The problem is that if
an untrapped error occurs in your code, all Public Variables are reset to
their default values, e.g. zero for numeric variables, zero-length string
for string variables.

Since I normally use a hidden Form, I store values in Controls on the hidden
Form. These values are not reset when untrapped errors occur and can be
accessed by either VBA code or queries.

In one of my databases, I have a Log-In Form (for identification, not
security), I simply hide this Log-In Form after identification and store
values on this Log-In Form.
 
Back
Top