Solved

# Finding string value in select case ms access

Posted on 2009-12-28
485 Views
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?

0

LVL 4

Expert Comment

If isnumeric(txtZip)
' US Postal Code
else
0

LVL 4

Accepted Solution

Hmm, something odd went on there, should have been:
``````If isnumeric(txtZip)
' US Postal Code
else
End If
``````
0

LVL 75

Expert Comment

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

Author Comment

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

Expert Comment

Well, then sekrin's 2nd post shows how to do that.

mx
0

Author Comment

I would like to use the select case if possible - can this be done?
0

LVL 75

Assisted Solution

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

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

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

Expert Comment

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

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…