example using Enum in Acc2002?

T

Ted

Greetings,

Does anyone have an example of how to use Enum in
Acc2002? I know how to delcare an Enum:

Public Enum abc
a = 1
b = 2
End Enum

But how or when would you use this? What is the purpose
of Enum vs Type variable in Access 2002?
 
A

Allen Browne

Enumerations are useful where you want to hard-code a list of items to a
number.

Here's a very simple example that is kinda like using a constant instead of
trying to remember what number is each type of pet. The same thing happens
with the built in enumerations, such as vbSunday, vbMonday, ...

Enum MyList
dog = 1
cat = 2
End Enum
Public Function WhatPet(MyMember As MyList) As Integer
WhatPet = MyMember
End Function

Paste this example into a standard module.
Then open the Immediate window (Ctrl+G), and enter:
? WhatPet(
At that point, your enumeration is offered, so you don't have to remember
the code for each one.

BTW, you can also call the built-in enumerations. For example, if you need
the same code for two buttons that open a report in normal or preview, you
could create a function and declare it like this:
Function OpenTheReport(strDoc As String, lngView As acView)
and then call it like this:
Call OpenTheReport("Report1", acViewPreview)
 
T

Ted

Thanks very much for getting back to me on this and for
all the information and explanations. This is hot! I
will be exploiting Enum to the hilt. This is real
convenient for coding. I really can't get over Acc2002.
It has so many improvements over the previous versions,
especially in the Sql, like I can write Tsql type
statments like

Select Count(fld3) From (Select fld1, fld2, fld3 From tbl1
t1 Join tbl2 t2 On t1.fld1 = t2.fld2 Where...)

I imagine Acc2003 has even more cool stuff, but the
ultimate will be the .Net version of Access with
inheritance and stuff. Right now I have to write VB.Net
apps which have to call Access for crunching numbers (I
can't think of anything that is easier for granular
crunching of numbers and then reporting than Access).
 
Top