[AccessD] Constants

Stuart McLachlan stuart at lexacorp.com.pg
Sun Oct 3 16:58:15 CDT 2021


The way I do it:
Public constants (those used outside of the module they are declared in) are all at the top of 
modGeneral

Where they vary accoring to environment, use compiler directives:

#Build = 1   ' 1 for Development, 2 for Client A .......
...
#IF #BUILD = 1 then
    Const CON_APP_PATH = C:\XYZ
    Const CON_XL_EXPORT_PATH = C:\XYZ\XLS
    Const CON_TEMPLATE_PATH = "C:\Users\Arthur\My Documents\Custom Office 
Templates"
#ELSE
    Const CON_APP_PATH = C:\ABC
    Const CON_XL_EXPORT_PATH = C:ABC\XLS
    Const CON_TEMPLATE_PATH = "C:\Users\Fred\My Documents\AppName\Custom 
Office Templates"
#END IF

However, I wouldn't hard code any of the above constants.

Intead of  CON_APP_PATH I'd use CurrentProject.Path

For things like users "documents" directory, I'd use "Known Paths" and/or environment 
variables . Here's my three main ones:

Public Function Desktop() As String
    Dim wss
    Set wss = CreateObject("WScript.Shell")
    Desktop = wss.SpecialFolders("Desktop")
    Set wss = Nothing
End Function

Public Function MyDocuments() As String
    Dim wss
    Set wss = CreateObject("WScript.Shell")
    MyDocuments = wss.SpecialFolders("MyDocuments")
    Set wss = Nothing
End Function

Public Function TempDir() As String
    TempDir = Environ("TEMP")
End Function






More information about the AccessD mailing list