Assigning a category to a range of numbers

sauk304

New member
Local time
Today, 15:07
Joined
Aug 5, 2010
Messages
5
Hi all, this doesn't seem too complex but I'm having trouble finding a similar situation online.
I have a query with a field called MAD. I would like to turn these MAD into a category index.
For example:
MAD: Number of MAD-> assigned Category value.
    • 0-50 -> A
    • 51-100 -> B
    • 101-500 -> C
    • 501-999999> D
So I would have an expression in a new field in that query with the index values. If anybody could assist, that would be much appreciated. I'm sorry for the simplicity of this. Thank you in advance.
 
What you need is a function:
Code:
Public Function GetCategory(madNo As Variant) As Variant
    Select Case Nz(madNo, vbNullString)
        Case 0 To 5
            GetCategory = "A"
        Case 51 To 100
            GetCategory = "B"
        Case 101 To 500
            GetCategory = "C"
        Case 501 To 999999
            GetCategory = "D"
        Case vbNullString
            GetCategory = Null
        Case Else
            GetCategory = "-Uncategorised-"
    End Select
End Function
You would call this function as an alias field in your query as follows:
Code:
AliasName: GetCategory([MAD])

You can call AliasName anything you want.
 

Users who are viewing this thread

Back
Top Bottom