?
Solved

Finding string value in select case ms access

Posted on 2009-12-28
11
Medium Priority
?
537 Views
Last Modified: 2012-05-08
I am  using a case statement to determine the number of days to ship an item depending on the zipcode of the customer - so far I have a field called txtZip:

Select Case txtZip
Case 0 To 26999, 40000 To 49999, 55000 To 58999, 60000 To 62999
     DTS = 3 'DTS is Days To Ship
Case 27000 To 39999
     DTS = 2
Case 50000 To 52999, 63000 To 79999
     DTS = 4
Case 59000 To 59999, 80000 To 89999
     DTS = 5
Case 90000 To 96199
     DTS = 6
End Select

This works for US zipcodes but I need to included Canadian postal codes.  These start with letters.  

1)  How do format the case for searching for a string that starts with letters?  
2)  If I wanted to do the canadian postal codes with an IF statement - what would I use to find postalcodes strings that start with a letter?

Thanks for your help.
0
Comment
Question by:johnmadigan
  • 5
  • 4
  • 2
11 Comments
 
LVL 4

Expert Comment

by:sekrin
ID: 26131280
If isnumeric(txtZip)
 ' US Postal Code
else
0
 
LVL 4

Accepted Solution

by:
sekrin earned 375 total points
ID: 26131289
Hmm, something odd went on there, should have been:
If isnumeric(txtZip)
 ' US Postal Code
else
 ' Canadian Postal Code
End If

Open in new window

0
 
LVL 75
ID: 26132217
I don't think you are going to be able to deal with CAN zips in the same way with the Case Statement approach, because there are infinitely more combination with CAN zip codes.

mx
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:johnmadigan
ID: 26132305
It looks like there are 18 letter codes for Canada - but I will be setting up shipping zones - so codes starting with a-n would be in the same shipping region & o-y would be in another zone.  I just need to be able to look at the first part of the string to determine which zone to put it in.  I would like to use the case statement but could do with the IF.
0
 
LVL 75
ID: 26132346
Well, then sekrin's 2nd post shows how to do that.

mx
0
 

Author Comment

by:johnmadigan
ID: 26132878
I would like to use the select case if possible - can this be done?
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 375 total points
ID: 26132921
Yes ... like sekrin showed:

If isnumeric(txtZip)
 ' US Postal Code
Select Case txtZip
Case 0 To 26999, 40000 To 49999, 55000 To 58999, 60000 To 62999
     DTS = 3 'DTS is Days To Ship
Case 27000 To 39999
     DTS = 2
Case 50000 To 52999, 63000 To 79999
     DTS = 4
Case 59000 To 59999, 80000 To 89999
     DTS = 5
Case 90000 To 96199
     DTS = 6
End Select

else

 ' Canadian Postal Code - Select Case statements here for CAN

End If
0
 

Author Comment

by:johnmadigan
ID: 26133187
I can figure out the case statement for the US but need the syntex for searching for string values for Canada:

Something like
Case (a*) to (n*)
     DTS = 8
Case (o*) to (y*)
    DTS = 10
End Select

I just need the first letter to determine the zone.  I don't know how to use wild cards in the case starment -

thanks,
0
 

Author Comment

by:johnmadigan
ID: 26138426
I did some more research and was able to make the case statement work using:

Case txtZip Like "[a-n]*"
   DTS = 8
Case txtZip Like "[o-y]*"
   DTS = 10
End Select

Thanks for your help anyway -
0
 
LVL 75
ID: 26139282
ok.  However, we did answer part of your question.  I thought you knew how to do the Case for the CAN codes, sorry.

mx
0
 

Author Closing Comment

by:johnmadigan
ID: 31670872
I had the case statement working I just needed help with the syntax for looking at strings using wildcards - I'll be more specific next time.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question