Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VB6 "Constant Expression Required" Error on Enumeration

VB6 "Constant Expression Required" Error on Enumeration

VB6 "Constant Expression Required" Error on Enumeration

I have a solution to an old thread (thread710-62825) in case someone is still having this trouble like I was.

The original post was:
Galford (Programmer)

I have the following enumeration defined in a class:

'Class module to handle connection to database
Public Enum DBLoc
DBLocal = 1
DBServer = 2
End Enum

From time to time, I'll get a compile error stating Constant Expression Required even though it is defined in the class.

Is this a bug or did I do something wrong? Any help would be appreciated.


This turned out to be a bug in VB, and I had to search around a bit to get this answer.

1. Put the cursor on the highlighted value
2. Type Shift - f2.
3. On the enum line, put the cursor after 'enum'
4. Type spacebar and then arrow down.

You will have to restart the compile, but it will work again after that.

Thanks to "David Carr" <David_Carr@NoSpamCanada.Com> for providing the answer.

If anyone has a better or more permanent solution for this bug, please let us all know.


RE: VB6 "Constant Expression Required" Error on Enumeration

What I usually do is just cut it the enum block and move down a line or two and paste it back in. Works most of the time, but not always. I'll see if your solution works better, though it will take a while, as it may go a few weeks with no problems, and then several times on one day.

RE: VB6 "Constant Expression Required" Error on Enumeration

I've found that restarting the IDE always works.

RE: VB6 "Constant Expression Required" Error on Enumeration

I just had the problem again, and tried the solution posted by jamesste  and it works.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close