Public Constants

V

Vsn

Hello there,

How can I achieve to set Constants values, which I can than use throughout
the application, when I open and Access DB.

I can set them in a Module but how do I get the database to read them at
startup? In VB60 I can add a module called 'Main' which is always
read/executed before anything else happens, so here you can set the const?

Thx,
Ludovic
 
A

Allen Browne

If you place the constants in the General Declarations section of a standard
module (i.e. at the top, just after the Option statements, in a module that
shows up on the Modules tab of the Database window), they will in any *code*
anywhere in your application.

They will not be available in other contexts (such as in queries, or in the
Control Source of at text box.) If you really need that, you could write a
function to return the value, e.g.:
Public Const gstrcDeveloper = "Vsn"
Public Function WhosTheDeveloper() As String
WhosTheDeveloper = gstrcDeveloper
End Function

Access 2007 includes TempVars - variables you can set at application
startup, and use anywhere in the application, including in macros, queries,
or the Control Source expressions.
 
R

Rick Brandt

Vsn said:
Hello there,

How can I achieve to set Constants values, which I can than use
throughout the application, when I open and Access DB.

I can set them in a Module but how do I get the database to read them
at startup? In VB60 I can add a module called 'Main' which is always
read/executed before anything else happens, so here you can set the
const?
Thx,
Ludovic

if you set a concstant in a module then it is already availabel everywhere
in your app. You don;t have to do anything else..

Public Const myStringConstant = "something"
 
V

Vsn

Allan, thx for the help. For the 2007 version I will have to save a bit
longer. In the earlier days I had everything dodgy but now tempt to have all
original copies. I do look out to try and see the new versions of office.

Ludovic
 
V

Vsn

Thx again, worked.
Ludovic

Rick Brandt said:
if you set a concstant in a module then it is already availabel everywhere
in your app. You don;t have to do anything else..

Public Const myStringConstant = "something"
 
Top