using global constants

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

Guest

Once a global constant is defined, how can I use it in a Form or Report? I
want to create a company name constant and then use it globally on each
form/report, etc.

Thanks for any help.
Dave
 
If you have several you may want to create a module just for your Globals.
Declare Globals just as you would any other variable but change out Dim for
Global.
Example:

Local variable declaration =
Dim strCompanyName As String

Global variable declaration =
Global strCompanyName As String

And then anywhere in your database you want be it module, form, report,
etc... you can access the variable.
 
dave said:
Once a global constant is defined, how can I use it in a Form or Report? I
want to create a company name constant and then use it globally on each
form/report, etc.


Global variables are VBA variables that are declared Public
in a standard module's declaration section (before any
procedures).

However, they are VBA variables and are not in the name
space of queries or form controls, which use the Expression
Service, not VBA. The only VBA declared thingies that are
recognized by the expression service are Public Functions in
standard modules.

What all that means is that a query or a text box expression
has to use a Function to retrieve the value of a global
variable. For example: If you have a standard module with

Public gstrName As String
Public Function GetName() As String
GetName = gstrName
End Function

Then VBA code in any module, even a class module behind a
form/report, can just use gstrName as if were declared
locally. BUT a query or text box expressiom must use
GetName() to retreive the value in the variable.
 
Back
Top