Variables and constants both represent particular values. However, a variable’s value will change as circumstances dictate, but a constant will always retain the same value. As an example, the value of pi would certainly not change.
You declare a variable with the keyword Dim, and a constant with the keyword Const. There are also constants called intrinsic constants that are built into Access, VBA, or the ADO library. The origin of these intrinsic constants can be identified by their prefix. For example:
The prefix vb refers to a Visual Basic constant.
The prefix ac refers to an Access constant.
The prefix ad refers to an ADO constant.
VBA has hundreds of such constants built in. As an example, open the Object Browser and do a search for constants. Then, click on one of the VBA libraries. You will get something resembling Figure 8-1. These constants should work properly anywhere in your code.
Again, if you use the Object Browser and click on one of the Access libraries, you will get something that looks like Figure 8-2. Before version 2000 of Access, these names used the convention of the letter A followed by an underscore, for example, A_Next or A_ Record.
We will be exploring ADO constants as we progress further through the book.