Microsoft Access - Create Your Own Enum Types To Make It Easier To Select And Use Constant Values (2000/2002/2003)


If you have set constants that you're always using, you should consider adding them to an Enum type. An Enum is nothing more than one or more constants that you group under an object variable. The following code creates a simple Enum that defines cold, warm, and hot temperatures:


  • Public Enum intTemps
  • intCold = 0
  • intWarm = 68
  • intHot = 90
  • End Enum

With this Enum in place, you can access any one of the temperature values using the syntax enumName.enumVal, like so:


  • If curTemp >= intTemps.intWarm And _
  • curTemp < intTemps.intHot Then _
  • MsgBox ("Today is a nice, warm day")

As an added bonus, you'll receive Intellisense help as soon as you type an Enum name to minimize syntax errors.

Go back