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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerated types in Access 97 2

Status
Not open for further replies.

Cads

Technical User
Jan 17, 2000
40
0
0
GB
I've been sent a useful set of procedures by another Access developer which were written in Access 95 and (according to my source) worked fine. When I transfered the code into Access 97, it baulked at the Enumerated Type code with a syntax error:

example

Private Enum CharType
CharAlpha = 1
CharNumeric = 2
CharSpace = 3
CharOther = 4
End Enum

I've since discovered from the MS Knowledgbase that at Access 97 the 'Enum' object was abandoned but it doesn't tell me what replaced it - if anything! I know Enum is recognised by VB5 upwards so Microsoft still supports the code but not in Access 97. Any ideas how I can either reference the VB code library or emulate Enum in another way?
 
I don't think Enum was abandoned, 97 just added limits to the name you can give to your Enum so that they don't conflict with Access or VB reserved words or with enums installed in other libraries. Perhaps CharType is a reserved word in one of the libraries already referenced in your DB. Try replacing the CharType enum to a word you know won't be in conflict, like CharTypeMine.
 
Unfortunately not the case. Tried changing the name of the Enum to a few different names but VBa still doesn't like the syntax.

Knowledgebase article 160500 says how the keyword Enum is now restructed without clearly explaining how. I'm still fairly certain its Enum that it doesn't recognise in the context it is.

Thanks for your reply, though.
 
Enum exists in Access 2000 VBA in the form you want to use it.

So far as I remember it does not exist in Access 97 VBA and I had thought it did not exist in earlier versions.

KB 160500 is concerned with the conversion of an Access 2 database to later versions. enum was not available in Access 2 as a keyword. However, it was used as a variable name in the Northwind example database. When you try to convert that database to a later version of Access the use of enum as a variable name becomes illegal because it is now a reserved word.

However, the fact that enum is reserved in Access 97 does not mean that it is implemented. They may have just been preparing the ground for Access 2000.

Ken
 
Thanks, Ken. I am using 2000 and knew Enum was available, but didn't have a copy of 97 available to see if it would throw the same error Cads had.
Sorry I couldn't be more help, Cads.
 
If you want a work around, I've seen it suggested that you can change your Enums to Public Consts.
 
To work even further around, public constants are for some obscure reasons not allowed in class modules. The is, however, a "class instance" in Access VBA. So, as a workaround, I sometimes create property routines to return the constant values.

So within clsText you can write:
Code:
Public Property Get CharAlpha As Long
 CharAlpha = 1
End Property

and the use

Code:
clsText.CharAlpha

from anywhere in your code.

Best regards
 
Thanks for that star

Cads, the others have given helpful advice as well so perhaps you owe them a star as well.

Best wishes
 
Thanks for your various comeents. Decided to restructure the code to use Public Constants. It's worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top