MS-Access / Getting Started

Constants

Constants are, in effect, variables that do not change. They hold values that are used repeatedly within your code and effectively provide shorthand for that particular constant value.

You use the same rules to create a constant as you do to create variables, but you cannot assign a new value to that constant from within your code as you can with a variable.

Const Path_Name = "C:\temp\"

The preceding code sets up a constant called Path_Name, which here always has the value: C:\temp\. Thus, you can use this in your program every time you want to use that particular path.

The Access object model also has predefined constants, which you can see by using the Object Browser. In the Access object model, all constants begin with the letters "xl" to denote that they are part of the Access object model-for example, xlSaveChanges or xlDoNotSaveChanges. The Object Browser also shows the actual value of the constant at the bottom of the browser window.

[Previous] [Contents] [Next]