Referencing Public Variables

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

Guest

I have declared a public variable in a standard module and I thought I could
use it thru out my App;ication. I would like to use it in a query as the
criteria and I'd like to use it in a control on a form. Do I need a special
way to refernce it or can I only use the vars in code and not in forms or
queries?? Any other insights you have pertaining to variables would be
helpful. I have a basic knowledge of Dim and public in form/report modules.
Thanx
 
If you want to use the value of a variable in a query, you must write a
public function that returns the value of that variable, and then use that
function in the query.

Suppose that you're public variable is named PubVar. The function would look
like this:

Public Function GetPubVar()
GetPubVar = PubVar
End Function

Note that public variables are prone to be "reset" to the default value if
an unhandled error occurs within the code when it runs. So it's possible to
lose such values at times.
 
Thanks Ken I hadn't thought of that. I suppose I do the same thing in a
control on a form?? Control source: =FunctionThatReturnsValue ??
 
Yes.

Gil said:
Thanks Ken I hadn't thought of that. I suppose I do the same thing in a
control on a form?? Control source: =FunctionThatReturnsValue ??
 
Back
Top