Results 1 to 2 of 2
2005-03-16, 14:12 #1
- Join Date
- Jan 2001
- Alzano Lombardo, Italy
- Thanked 0 Times in 0 Posts
Constants used throughout an application (2000)
I know you cannot use functions in expressions assigned to constants and you cannot assign expressions to variables outside of procedures so how can I declare constants to be used throughout an application?
The startup form in the attached mdb opens with the message: Compile error. Constant expression necessary.
The public constants declared in Module1 are used, e.g., in several AfterUpdate events for text boxes in the Gruppo4 form.
2005-03-16, 14:19 #2
- Join Date
- Mar 2002
- Thanked 28 Times in 28 Posts
Re: Constants used throughout an application (2000)
The problem is not in the startup form, but in Module1. Declarations such as
Public Const lngRed As Long = RGB(255, 0, 0)
are not allowed because they use a function (RGB) in the definition of a constant. You must use the result of the function. But in this situation, you don't need these constants at all, because VBA has built-in constants vbRed, vbGreen, vbYellow and vbWhite, so you can replace lngReds with vbRed throughout your code, etc.