Solved

Access String

Posted on 2013-05-23
3
229 Views
Last Modified: 2013-05-23
I'm using the folling code to replace zero after only the first occurance of a dash:
 Replace([FieldName],"-0","-",1 ,1)
However the codes does not work in all cases. For Example:

75-01-0140 Before
75-1-0140 After - Ok

75-10-0140 Before
75-10-140 Incorrect -- Only if  zero after the first dash other wise do nothing
75-10-0140 After - Ok
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
  • 2
3 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39191320
Try this:

Function FormatData(strInput as string) as string
      dim s() as string
      s = split(strinput, "-")
      s(1) = Val(s(1))
      formatData = join(s,"-")
End Function

Open in new window


You can call it from a query as follows:

UPDATE YourTable SET YourField = FormatData("" &  YourField )

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39191331
To prevent errors in some special cases, such as no dashes:

Function FormatData(strInput as string) as string

      If Len(strInput) = 0 or Instr(1,strInput,"-") = 0 then
            formatdata = strInput
            exit function
      end if

      dim s() as string
      s = split(strinput, "-")
      s(1) = Val(s(1))
      formatData = join(s,"-")
End Function

Open in new window

0
 

Author Closing Comment

by:shieldsco
ID: 39191446
Thanks
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 …

726 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