Defining a variable

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

Guest

I am having trouble with something I think is simple. Here is what I want to
do. I want to create a module that is simply a list of my commonly used
pieces of information, which I only currently have one, but nonetheless, I
want to use that in many queries, forms, reports. How should I set up the
module and then how do I reference it elsewhere. Right now, I simply have:

txtPLAN_YR = "2006"

in several places. I want to make that go away. Please help.
 
Hi Biggles,

Many of my databases have a module called vbGlobals which contains
(among other things) constant declarations for this sort of thing:

Public Const COMPANY_NAME = "Acme Firework Corp"

Another approach - if this is data that changes from time to time - is
to have a table for your settings:

tblSettings
SettingName - Text, primary key
SettingValue - Text

with records such as
"Plan Year", "2006"

You can then use DLookup() to retrieve the value wherever it's needed.
 
Of course, my first reply is "Wow, you got to work on Acme Firework?" Sorry,
had to be said.

I would like to use that public const method, but how do I reference in
other modules? Is it something like

VBGLOBALS.COMPANY_NAME

?
 
As long as it's declared in an ordinary module (as against a form or
class module), just use COMPANY_NAME.

The capital letters aren't compulsory: I like to use them to make it
clear that this is a constant; I'd use CompanyName or strCompanyName for
a variable.
 
The capital letters aren't compulsory: I like to use them to make it
clear that this is a constant; I'd use CompanyName or strCompanyName for
a variable.

Of course, strict Hungarian would make this gc_strCompanyName


Tim F
 
Back
Top