• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 548
  • Last Modified:

Finding string value in select case ms access

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
johnmadigan
Asked:
johnmadigan
  • 5
  • 4
  • 2
2 Solutions
 
sekrinCommented:
If isnumeric(txtZip)
 ' US Postal Code
else
0
 
sekrinCommented:
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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
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.

 
johnmadiganAuthor Commented:
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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Well, then sekrin's 2nd post shows how to do that.

mx
0
 
johnmadiganAuthor Commented:
I would like to use the select case if possible - can this be done?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
johnmadiganAuthor Commented:
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
 
johnmadiganAuthor Commented:
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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
johnmadiganAuthor Commented:
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
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now