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!

Case Statement Not working

Status
Not open for further replies.

ste4en

Technical User
Aug 1, 2001
69
I am trying to use a Case statement however the red part as below is being ignored. Can anyone point out my error. Thanks; Steve

Code:
Select Case (myActivityCode)
  Case 201900
    CostCodeN = "201900"
  Case 201901
    CostCodeN = "201901"

[COLOR=red]
Select Case Left(myActivityCode, 3)
  Case "950"
    CostCodeN = "950000"
  Case "955"
    CostCodeN = "950000"
  Case "959"
    CostCodeN = "959000"
[/color]
End Select
  
  Case Else
  CostCodeN = Left(myActivityCode, 1) & "00000"

End Select
End Function
 



Hi,

let me indent for emphisis
Code:
    Select Case (myActivityCode)
      Case 201900
        CostCodeN = "201900"
      Case 201901
        CostCodeN = "201901"

       'myActivityCode is [b]201[/b]901 - THEREFOR the Left 3 emphasized
       ' as you see, there are no "201" cases.
    
        Select Case Left(myActivityCode, 3)
          Case "950"
            CostCodeN = "950000"
          Case "955"
            CostCodeN = "950000"
          Case "959"
            CostCodeN = "959000"
        
        End Select
      
      Case Else
      CostCodeN = Left(myActivityCode, 1) & "00000"
    
    End Select

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Thanks Skip, I think you are saying that Case won't work here so how about IF's like this.

will Else: CostCodeN = Left(myActivityCode, 1) & "00000" capture everything that falls through the other IF's. Thanks


Code:
If (myActivityCode) = "201900" Then
    CostCodeN = "201900"
    Else
If (myActivityCode) = "201901" Then
    CostCodeN = "201901"
    Else
If Left(myActivityCode, 3) = "950" Then
    CostCodeN = "950000"
    Else
If Left(myActivityCode, 3) = "955" Then
    CostCodeN = "950000"
    Else
If Left(myActivityCode, 3) = "959" Then
    CostCodeN = "959000"
    Else: CostCodeN = Left(myActivityCode, 1) & "00000"

End If
End If
End If
End If
End If

End Function
 




I can evaluate SYNTAX.

Only YOU know what LOGIC your code must execute. Does that LOGIC meet your requirement? Did you test it?

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
ste4en - I think you need to step back and take some time to learn the basic syntax of the VB language.

 
learning is what i am trying. I will use my nested IIF in the query.
thanks anyway.
 
I think the OP wanted this:
Code:
Select Case myActivityCode
Case 201900
  CostCodeN = "201900"
Case 201901
  CostCodeN = "201901"
Case Else
  Select Case Left(myActivityCode, 3)
  Case "950"
    CostCodeN = "950000"
  Case "955"
    CostCodeN = "950000"
  Case "959"
    CostCodeN = "959000"
  Case Else
    CostCodeN = Left(myActivityCode, 1) & "00000"
  End Select
End Select

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH - That's exactly what I wanted Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top