using global constants

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
 
G

Guest

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.
 
M

Marshall Barton

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.
 

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

Similar Threads

global constants 7
Access 2010 Report Button 0
Constants 2
Global Constant values 1
global constants 4
Global Constants? 2
Calculating totals in access 1
How to access global variable EXPLICITLY 2

Top