By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,395 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,395 IT Pros & Developers. It's quick & easy.

Area Codes, this should work, right?

P: n/a
This always evaluates to the case else, even when the immediate window
shows true for the one of the other cases? I am using this same
syntax else, and it works? I
Select Case phonenum
Case Left(phonenum, 3) = "770"
Debug.Print "770 case" & phonenum

Case Left$(phonenum, 3) = 404
Debug.Print "404 case" & phonenum

Case Left$(phonenum, 3) = 678
Debug.Print "678 case" & phonenum

Case Else
Debug.Print "0ther case" & phonenum
phonenum = "1" & phonenum

End Select

Any help would be appreciated.

Tony
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
1. For consistency, change the two Left$ to Left
2. 404 and 678 need to be enclosed in double quotes

If your phone numbers begin with 1 + Area code your Select Case code will always
evaluate to the Else case. If your phone numbers begin with area code and you
don't have any phone numbers with area code 770, 404 or 678, your Select Case
code will always evaluate to the Else case.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Sean O" <ro*******@yahoo.com> wrote in message
news:9e**************************@posting.google.c om...
This always evaluates to the case else, even when the immediate window
shows true for the one of the other cases? I am using this same
syntax else, and it works? I
Select Case phonenum
Case Left(phonenum, 3) = "770"
Debug.Print "770 case" & phonenum

Case Left$(phonenum, 3) = 404
Debug.Print "404 case" & phonenum

Case Left$(phonenum, 3) = 678
Debug.Print "678 case" & phonenum

Case Else
Debug.Print "0ther case" & phonenum
phonenum = "1" & phonenum

End Select

Any help would be appreciated.

Tony

Nov 13 '05 #2

P: n/a
Sean O wrote:
This always evaluates to the case else, even when the immediate window
shows true for the one of the other cases? I am using this same
syntax else, and it works? I
Select Case phonenum
Case Left(phonenum, 3) = "770"
Debug.Print "770 case" & phonenum Select Case Left(phonenum,3)
Case "770"
Debug.Print "770 case" & phonenum Case "404"
etc, etc, etc


Case Left$(phonenum, 3) = 404
Debug.Print "404 case" & phonenum

Case Left$(phonenum, 3) = 678
Debug.Print "678 case" & phonenum

Case Else
Debug.Print "0ther case" & phonenum
phonenum = "1" & phonenum

End Select

Any help would be appreciated.

Tony


Nov 13 '05 #3

P: n/a
Ok, now I get it. I see now that evauluation was happening in the wrong place!

Thanks.

Salad <oi*@vinegar.com> wrote in message news:<i6******************@newsread1.news.pas.eart hlink.net>...
Sean O wrote:
This always evaluates to the case else, even when the immediate window
shows true for the one of the other cases? I am using this same
syntax else, and it works? I
Select Case phonenum
Case Left(phonenum, 3) = "770"
Debug.Print "770 case" & phonenum

> Select Case Left(phonenum,3)
> Case "770"
> Debug.Print "770 case" & phonenum

Case "404"
etc, etc, etc


Case Left$(phonenum, 3) = 404
Debug.Print "404 case" & phonenum

Case Left$(phonenum, 3) = 678
Debug.Print "678 case" & phonenum

Case Else
Debug.Print "0ther case" & phonenum
phonenum = "1" & phonenum

End Select

Any help would be appreciated.

Tony

Nov 13 '05 #4

P: n/a
Sean O wrote:
Ok, now I get it. I see now that evauluation was happening in the wrong place!

Thanks.


Yeah. In FoxPro you could string Case like a bunch of If statements.
Not in Access. Probably why IF is used far more often than CASE

Nov 13 '05 #5

P: n/a
ro*******@yahoo.com (Sean O) wrote in
news:9e**************************@posting.google.c om:
This always evaluates to the case else, even when the
immediate window shows true for the one of the other cases? I
am using this same syntax else, and it works? I
Select Case phonenum
Case Left(phonenum, 3) = "770"
Debug.Print "770 case" & phonenum

Case Left$(phonenum, 3) = 404
Debug.Print "404 case" & phonenum

Case Left$(phonenum, 3) = 678
Debug.Print "678 case" & phonenum

Case Else
Debug.Print "0ther case" & phonenum
phonenum = "1" & phonenum

End Select

Any help would be appreciated.

Tony


You must have learnt select case in dBase III. I did too, and I
constantly make the same mistake in Access.

Access wants to see
select case left$(phonenum,3)
case "770"
case "404"
case "670"
case else
end select

you only get the else because access treats your first option as
(phonenum = (left$(phonenum,3) = "770"))
which evaluates to False.

Bob Quintal
Nov 13 '05 #6

P: n/a
Chuck Grimsby <c.*******@worldnet.att.net.invalid> wrote:
Don't forget that you can also do things in Access like:

Select Case True
Case Left$(phonenum, 3) = "770"
'Do something
Case Left$(phonenum, 4) = "4041"
'Do something else
Case Left$(phonenum, 5) = "67812"
'Do yet another thing
Case Else
'When all else fails....
End Select


Interesting idea. Identical to If and IFElse though.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.