Results 1 to 2 of 2
  1. #1
    Bronze Lounger
    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts