Change If Statement to a Case Statement

How do I change the following to a  Select case statement?

If ActivityCode = "sig32" And Agency = "HPD" Then
MsgBox "Contact HPD"

Else

End If

Open in new window

mickeyshelley1Asked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
This really doesn't fit Select Case ... since you have two different items (Activity Code and Agency) ... and only one condition.

Leave as is ...

mx
0
 
IrogSintaCommented:
May I ask why you want to change this to a Select Case statement when what you have suffices?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
All you need is this:

If ActivityCode = "sig32" And Agency = "HPD" Then MsgBox "Contact HPD"
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Patrick MatthewsCommented:
As indicated above, this is not really a candidate for Select Case, which only evaluates one variable at a time.

You could do something like this:

Select Case ActivityCode
    Case "sig32"
        If Agency = "HPD" Then
            MsgBox "Contact HPD"
        Else
            ' do something else
        End If
    Case Else
        ' Whatever
End Select

Open in new window


However, that's no real improvement on what you already have :)
0
 
mickeyshelley1Author Commented:
This is just a part of the code, the complete code will have multiple if statements and I figured that a case statement would be a little less cluttered and more efficient.
0
 
IrogSintaCommented:
You could do this:
Select Case TRUE
    Case ActivityCode = "sig32" And Agency = "HPD"
        ....
    Case ...
         ....
End Select
0
 
mickeyshelley1Author Commented:
Are there any performance considerations in a scenario with multiple ELSEIF  that would make a case statement a better choice; that is the primary reason for my question
0
 
IrogSintaCommented:
I don't think there is a performance difference. If there is, it would be negligible.  I understand what you mean about less cluttered. I prefer using Select Case to multiple If ElseIf statements myself.
0
 
Jeffrey CoachmanMIS LiasonCommented:
<no points wanted>

From what I have read, a "One Variable" Case Select will always run faster than the corresponding If-Then-Else

But like IrogSinta, my guess is that the real world performance difference will not be of any real consequence.

I'm a bit old school, but I will admit that the Case Select can look neater.

But I tend to go with If/then/else because it is easier to understand in "Human" terms.
For example, the human request:
"If the Price is 2, then make the price box red"
...converts almost verbatim to:
If Price=2 then
    price.Backcolor=VBred
end if
;-)

But again, most current developer will use Select Case when the need is clear...
Again, I am a bit old school.

;-)

Jeff
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.