Part | Description | |
Public | Optional. Keyword used at module level to declare constants that are available to all procedures in all modules. Not allowed in procedures. | |
Private | Optional. Keyword used at module level to declare constants that are available only within the module where the declaration is made. Not allowed in procedures. | |
constname | Required. Name of the constant; follows standard variable naming conventions. | |
type | Optional. Data type of the constant; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported), Date, String, or Variant. Use a separate As type clause for each constant being declared. | |
expression | Required. Literal, other constant, or any combination that includes all arithmetic or logical operators except Is. |
' Constants are Private by default.
Const MyVar = 459
' Declare Public constant.
Public Const MyString = "HELP"
' Declare Private Integer constant.
Private Const MyInt As Integer = 5
' Declare multiple constants on same line.
Const MyStr = "Hello", MyDouble As Double = 3.4567
Example (Microsoft Access)
In Microsoft Access, you cannot declare public constants in the Declarations section of a class module. Constants in a class module must be private. You can declare both public and private constants in the Declarations section of a standard module.
' In class module.
Const conCommission As Single = .08
' In standard module.
Const conErrorNumber As Integer = 91
Public Const conAddress As String = "8421 58th Avenue, College Park, MD"