Go Back   Access World Forums > Microsoft Access Reference > Microsoft Access Tutorials

Closed Thread
Thread Tools Rate Thread Display Modes
Old 07-05-2011, 07:06 PM   #1
Newly Registered User
ChrisO's Avatar
Join Date: Apr 2003
Location: Brisbane, Australia
Posts: 3,202
Thanks: 7
Thanked 274 Times in 195 Posts
ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice
Organisation of Public Constants.

Organisation of Public Constants.

Keeping track of Public Constants can be difficult.
They do not lend themselves to easy organisation and we can not use Intellisense to display them.

The method presented here is to create small class modules to contain related constants.
We can then combine those related class modules into a single Constants class module.

For example:-

Class 1:
Class clsConstFill …
Option Explicit
Option Compare Text

Public SOLID       As Long

Private Sub Class_Initialize()

    SOLID = 0
End Sub
Class 2:
Class clsConstPen…
Option Explicit
Option Compare Text

Public PS_SOLID       As Long
Public PS_DASH        As Long
Public PS_DOT         As Long
Public PS_DASHDOT     As Long
Public PS_NULL        As Long

Private Sub Class_Initialize()

    PS_SOLID = 0
    PS_DASH = 1
    PS_DOT = 2
    PS_DASHDOT = 3
    PS_NULL = 5
End Sub
Class 3:
Class clsConstVbColours…
Option Explicit
Option Compare Text

Public BLACK   As Long
Public RED     As Long
Public GREEN   As Long
Public YELLOW  As Long
Public BLUE    As Long
Public MAGENTA As Long
Public CYAN    As Long
Public WHITE   As Long

Private Sub Class_Initialize()

    BLACK = vbBlack
    RED = vbRed
    GREEN = vbGreen
    YELLOW = vbYellow
    BLUE = vbBlue
    MAGENTA = vbMagenta
    CYAN = vbCyan
    WHITE = vbWhite
End Sub

Now combine the Classes:
Class clsConstants…
Option Explicit
Option Compare Text

Public Fill   As New clsConstFill
Public Pen    As New clsConstPen
Public Colour As New clsConstVbColours

Private Sub Class_Terminate()
    Set Fill = Nothing
    Set Pen = Nothing
    Set Colour = Nothing
End Sub

Behind a Form…
Option Explicit
Option Compare Text

' Add one Class Constants.
Public Constants As New clsConstants

Private Sub Form_Open(ByRef intCancel As Integer)
    Me.Section(acDetail).BackColor = Constants.Colour.YELLOW
End Sub

Private Sub cmdSetDetailToRed_Click()
    Me.Section(acDetail).BackColor = Constants.Colour.RED
End Sub
Note in the above Form code:
Class Constants is instantiated when the Form is opened.
The word ‘Constants’ must be typed manually followed by a period.
A list of Constants members is produced; Colour, Fill and Pen.
Select Colour followed by a period.
A list of Colour members is produced.
Select the Colour Constant required, in this case; YELLOW or RED.

The use of upper case for the resulting constant is not mandatory.
However, it does give a clue when we hit the end CONSTANT and it also complies with constants used in API calls.
So, if we CamelCase up to the final CONSTANT we know then we are at the end of the selection process.

It follows that we can also pre-class things like Fill with a parent class such as Line, Circle (whatever) that relates the Fill constants to a particular parent class.

I guess it should be pointed out that, strictly speaking, these are not really Constants, they can be written too.

If there are any questions, please ask them in the appropriate forum.


Access 2003, Win7, GMT +10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by ChrisO; 07-06-2011 at 04:19 AM.
ChrisO is offline  
The Following 2 Users Say Thank You to ChrisO For This Useful Post:
Kirkuleese (12-22-2015), moishy (06-19-2012)
Closed Thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Country organisation endri81 Tables 1 09-26-2010 05:42 PM
Tiered Organisation NathanSavidge Queries 3 04-26-2010 12:26 PM
Information Organisation Davidwaz Tables 1 03-29-2009 07:33 PM
Creating organisation charts??? brum_rich Reports 1 12-01-2008 10:02 AM
Self Organisation dynamictiger General 4 10-07-2002 10:44 AM

All times are GMT -8. The time now is 03:14 PM.

Microsoft Access Help
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post

Sponsored Links

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World