Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using an Enum to show descriptions?

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
0
0
US
Hey Folks

I have a field I use in a table that holds an integer value that described the status of a record. I would like to use an Enumeration to display the descriptions of those Status codes.

I have created a module-level Enum called Status in my application that has several values tied to it -- NoStatus = 0, Draft = 1, Approved = 2, etc.

How do I now use that Enum to display the description in a text field when I read the numeric value from the data record?

Thanks

Craig
 
Craig,

You have the right idea but you are going about it a little backwards. There is no way intercept the description of an enum at runtime, enums are specifically meant as a convience for developers to allow parameters and other data to be descriptive rather than numeric hard-coded values.

What you want to do is create a "lookup" table in your database that has two columns, nCode and strDesc. On the form load event, do something like this:

set rsStatus = cn.execute("select nCode, strDesc from tblStatus")

do while rsStatus.eof = false
cmbStatus.AddItem rsStatus("strDesc")
cmbStatus.ItemData(cmbStatus.newindex) = rsStatus("nCode")

rsStatus.MoveNext
loop

The reason you want to take this approach is so that in the future if you want to present the original record in a descriptive manner, you can simply join the first table to the lookup table and the result will be human readable.

Hope this helps.
 
Ah, I see. That explains why I couldn't find example of it in the help system. I have used the lookup table method many tiles but thought this time I would try an Enum. Too bad it won't do what I thought!

I appreiciate your help in setting me straight on what an Enum is used for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top