Defining constant values: how to?

  • Thread starter Thread starter mark s.
  • Start date Start date
M

mark s.

I'm making a Micorosoft Access 2000 DB.

What I want to do is to declare several constants (in VBA6) that I can
reuse in other code such as me.caption, instead of trying to use a table
to store just that information.

The constants that I wanted are Application Name, Version, Creation
Date, and Creator, for starts. I'm a newbie at (VB), although in the
past I used Access + VB6 but stopped for a couple of years.

I appreciate the help.

-Mark
 
I'm making a Micorosoft Access 2000 DB.

What I want to do is to declare several constants (in VBA6) that I can
reuse in other code such as me.caption, instead of trying to use a table
to store just that information.

The constants that I wanted are Application Name, Version, Creation
Date, and Creator, for starts. I'm a newbie at (VB), although in the
past I used Access + VB6 but stopped for a couple of years.

In the General, Declarations section of a standard module (for
application-wide accessibility) use a statement such as:

Public Const AppName As String = "The Application Name"

Note that I did not use "Application Name" as there can be no blanks in a
Variable name (there can be in a Field name, but I don't recommend it there,
either). In the module window, type in Const, place the cursor in that word,
and press F1 for Help on declaring Constants.

On the other hand, I've found a table just for "Info" of this kind to be a
useful development technique. And, if that is kept in a separate MDB to
which the user is linked, it can be used to save/maintain personal
preferences.

Larry
 
In the General, Declarations section of a standard module (for
application-wide accessibility) use a statement such as:

Public Const AppName As String = "The Application Name"

Note that I did not use "Application Name" as there can be no blanks in a
Variable name (there can be in a Field name, but I don't recommend it there,
either). In the module window, type in Const, place the cursor in that word,
and press F1 for Help on declaring Constants.

On the other hand, I've found a table just for "Info" of this kind to be a
useful development technique. And, if that is kept in a separate MDB to
which the user is linked, it can be used to save/maintain personal
preferences.

Larry
Thanks :) So how do I refrence these in the form code to use it?

Right now the code is:

Me.Caption = AppName _
& " " & AppVersion

and it is not working.
 
mark s. said:
Thanks :) So how do I refrence these in the form code to use it?

Right now the code is:

Me.Caption = AppName _
& " " & AppVersion

and it is not working.

What does "not working" mean? Are you getting an error? If so, what's the
error? Is the caption being set to something other than what you expected?
If so, are you sure that the constants are set correctly? Are you sure you
put the declarations into a standard module, as opposed to the module
associated with a form, or a class module?
 
What does "not working" mean? Are you getting an error? If so, what's the
error? Is the caption being set to something other than what you expected?
If so, are you sure that the constants are set correctly? Are you sure you
put the declarations into a standard module, as opposed to the module
associated with a form, or a class module?

Okay, It's working; I wasn't just looking at the caption. ^_^;

Now I want to use those set constants in form controls (like a label,
text box, listbox etc.). But I do not know how to output it in the
standard module (Not a class module, because I know that you can't use
"Public Const" from looking at the help file on it.)
 
mark s. said:
Okay, It's working; I wasn't just looking at the caption. ^_^;

Now I want to use those set constants in form controls (like a label, text
box, listbox etc.). But I do not know how to output it in the standard
module (Not a class module, because I know that you can't use "Public
Const" from looking at the help file on it.)

In the form's Load event, you'd put code like:

Me.MyLabel.Caption = AppName
Me.MyTextBox = AppVersion

Not sure how you'd intend to use the constants in a list box, although I
guess you could have something like:

Me.MyListBox.RowSourceType = "Value List"
Me.MyListBox.RowSource = AppName & ";" & AppVersion
 
Back
Top