Assistance with Select Case Statement

Ajayi32

Registered User.
Local time
Today, 04:56
Joined
Feb 21, 2001
Messages
26
Using Access 97

Code that works is as follows:

Function Category(arg As String) As String
Select Case arg
Case Is = "BNK"
Category = "A"
Case Is = "IND"
Category = "C"
End Select
End Function

Code that does not work is as follows:

Function Category(arg As String) As String
Select Case arg
Case Is = BNK, EMP, LFP, RTE, SAL, SLE, SUS
Category = "A"
Case Is = IND, PAL, PPP, RTL, RTN, SMB
Category = "C"
End Select
End Function

This is the latest version of the code that does not work. The arg is a type. I am wanting to return a Category value based on multiple types. Can I use the Select Case to do this?

Thanks for your input
/uh
 
The reason the second example doesn't work is that your string values are not enclosed in quotes, as they are in the first example. Also, if you're looking to compare arg to a sequence of string values, you don't need the "Is =", although it probably won't cause a problem. You may also want to include a "Case Else" clause to deal with unexpected or erroneous input. Try changing your code to something like this:

Function Category(arg As String) As String
Select Case arg
Case "BNK", "EMP", "LFP", "RTE", "SAL", "SLE", "SUS"
Category = "A"
Case "IND", "PAL", "PPP", "RTL", "RTN", "SMB"
Category = "C"
Case Else
[assign some value to Category]
End Select
End Function

Ajayi32 said:
Using Access 97

Code that works is as follows:

Function Category(arg As String) As String
Select Case arg
Case Is = "BNK"
Category = "A"
Case Is = "IND"
Category = "C"
End Select
End Function

Code that does not work is as follows:

Function Category(arg As String) As String
Select Case arg
Case Is = BNK, EMP, LFP, RTE, SAL, SLE, SUS
Category = "A"
Case Is = IND, PAL, PPP, RTL, RTN, SMB
Category = "C"
End Select
End Function

This is the latest version of the code that does not work. The arg is a type. I am wanting to return a Category value based on multiple types. Can I use the Select Case to do this?

Thanks for your input
/uh
 
Thank you so much. I think that was the only way I didn't try to get it to work. THANKS!!!!!!!!!!!!!!!!

AlanS said:
The reason the second example doesn't work is that your string values are not enclosed in quotes, as they are in the first example. Also, if you're looking to compare arg to a sequence of string values, you don't need the "Is =", although it probably won't cause a problem. You may also want to include a "Case Else" clause to deal with unexpected or erroneous input. Try changing your code to something like this:

Function Category(arg As String) As String
Select Case arg
Case "BNK", "EMP", "LFP", "RTE", "SAL", "SLE", "SUS"
Category = "A"
Case "IND", "PAL", "PPP", "RTL", "RTN", "SMB"
Category = "C"
Case Else
[assign some value to Category]
End Select
End Function
 

Users who are viewing this thread

Back
Top Bottom