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

Customized Switch Function 1

Status
Not open for further replies.

sxschech

Technical User
Jul 11, 2002
1,033
US
I thought I had seen a posting about a customized switch function, but haven't had luck finding it. Essentially it looked something like this:

EZSwitch(Group, "SA", "San Francisco","SB","San Bruno","DE","Denver","BO","Boston")

Rather than having to repeat the group each time as in the original switch
Switch([Group]="SA","San Francisco",[Group]="SB",","San Bruno",[Group]="DE","Denver",[Group]="BN","Boston")

Can it be done?
 
Why not simply a lookup table ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Usually do that, but thought this could be an easier setup than using iif statements on a report. The example seems like a candidate for a lookup table, but wanted to offer as a simple example.
 
A function like this ?
Code:
Public Function EZSwitch(myField, ParamArray myPairs())
Dim i As Long
For i = 0 To UBound(myPairs) - 1 Step 2
  If myField = myPairs(i) Then
    EZSwitch = myPairs(i + 1)
    Exit Function
  End If
  EZSwitch = myField
Next
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks so much. It works perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top