Solved

Access String

Posted on 2013-05-23
9
323 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
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
Does the field value always begin with xx-  (where x is any character)
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:shieldsco
Comment Utility
There should not be a change
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now