Solved

Access String

Posted on 2013-05-23
9
357 Views
Last Modified: 2013-05-23
I would like to remove the first number 1 after the first dash if there are two didgits between the first and second dashes and if the numbers are between 10 and 18. Example

75-11-0350 Before (there are two didgits between the first and second dashs and they are between 10 and 18)
75-1-0350 After

75-10-0350 Before (there are two didgits between the first and second dashs and they are between 10 and 18)
75-0-0350 After

75-19-1216-1031 Before (there are two didgits between the first and second dashs but they are not between 10 and 18)
75-19-1216-1031 After
0
Comment
Question by:shieldsco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 39191675
Does the field value always begin with xx-  (where x is any character)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39191692
revise the function that you have with this one


Function FormatData(strInput As String)
      Dim s() As String
      s = Split(strInput, "-")
      s(1) = IIf(Val(s(1)) >= 10 And Val(s(1)) <= 18, Mid(Val(s(1)), 2), Val(s(1)))
      FormatData = Join(s, "-")
End Function
0
 

Author Comment

by:shieldsco
ID: 39191799
It Coverted the following incorrect:

OriginalTBAppropriation      ConvertAppropriation
75-X-0131                         75-0-0131
75-X-0140                                      75-0-0140
75-X-0512                                      75-0-0512
75-X-0943                                      75-0-0943
75-X-0944                                      75-0-0944
75-X-0954                                      75-0-0954
75-X-0956                                      75-0-0956
75-X-5146-001                       75-0-5146-001
75-X-8250-001                       75-0-8250-001
0
Technology Partners: 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!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39191822
shieldsco,

you never mentioned that you have ALPHA values after the first dash..

we are not mind readers, so please give all the informations..


so what should be the result in case like that?  should it remain the same?
0
 

Author Comment

by:shieldsco
ID: 39191834
There should not be a change
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39191841
try this

Function FormatData(strInput As String)
      Dim s() As String
      s = Split(strInput, "-")
     
      If IsNumeric(s) Then
              s(1) = IIf(Val(s(1)) >= 10 And Val(s(1)) <= 18, Mid(Val(s(1)), 2), Val(s(1)))
      End If
     
      FormatData = Join(s, "-")
End Function
0
 

Author Comment

by:shieldsco
ID: 39191895
No conversion on the following -- the change however did convert the X values correctly

OriginalTBAppropriation      ConvertAppropriation
75-12-0955                      75-12-0955  Incorrect s/b 75-2-0955


OriginalTBAppropriation      ConvertAppropriation
75-X-0131                                      75-X-0131 correct
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39191907
oops, missed the (1), use this revised code


Function FormatData(strInput As String)
      Dim s() As String
      s = Split(strInput, "-")
     
      If IsNumeric(s(1)) Then
      s(1) = IIf(Val(s(1)) >= 10 And Val(s(1)) <= 18, Mid(Val(s(1)), 2), Val(s(1)))
      End If
     
      FormatData = Join(s, "-")
End Function
0
 

Author Closing Comment

by:shieldsco
ID: 39191971
Thanks
0

Featured Post

Technology Partners: 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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

710 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