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!

One Global Constant to Define Multiple Values 2

Status
Not open for further replies.

Spaniard

MIS
Jul 23, 2002
29
0
0
US
Is it possible to have a global constant represent multiple values? In a Before_Update sub, I want a warning to the user that the value they are about to enter is probably wrong.

The following may be more illustrative - the numbers represent machines that are seldom utilized...

Global Const Seldom_Used = {1, 2, 4, 7, 9}

 
Try this in a .bas (module)

Public Enum i
Value1 = 10
Value2 = 20
End Enum

Then in a form you can referrence it like

bebug.print i.value1
bebug.print i.value2

Returns
10
20
 
Why not just use an array? Typically in any application I build I will create a module level data type for what you are looking to do and so much more...

For example:

Type arrayType
count As Integer
Item(100) As String
End Type

Then when your application or form opens you can initialize an array with the machine numbers...

dim machinesSeldomUsed as arrayType

machinesSeldomUsed.Item(0) = 1
machinesSeldomUsed.Item(1) = 2
machinesSeldomUsed.Item(2) = 4
machinesSeldomUsed.Item(3) = 7
machinesSeldomUsed.Item(4) = 9
machinesSeldomUsed.count = 4

Then you can create a generic function that when called would tell you if a particular value exists in the array...

Public Function valueInArray(array2Check As arrayType, value2Check As String) As Boolean
Dim index As Integer

For index = 0 To array2Check.count
If array2Check.Item(index) = value2Check Then
valueInArray = True
Exit For
End If
valueInArray = False
Next index
End Function

From your form you would just call the function and act accordingly...

If valueInArray(machinesSeldomUsed, me.controlName) Then ...
Else ...
End If

The nice thing about this approach is that you can later add machines to the list or use it in any number of other ways.
 
Thanks for all your input...I like the enum approach, but Access 97 doesn't support it. I think the array will work.

Again thanks to all.

SKW
 
Another option would be to use a table. This has the advantage of allowing you to edit the list dynamically, and is about as native to Access as you can get.

Just my 2 cents. [morning] Sleep is for people with no caffeine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top