Jumat, 20 Januari 2017

Re: [MS_AccessPros] string functions

 

I would create a small user-defined function to handle this:

Public Function InsertChar(strIn As String, strInsert As String) As String
    Dim intI As Integer     'use to increment loop through the original string
    Dim strOut As String    'build this string to return from function
    strIn = Replace(strIn, strInsert, "")  'get rid of all inserted characters to start
    For intI = 1 To Len(strIn)
        strOut = strOut & Mid(strIn, intI, 1) & strInsert
    Next
    InsertChar = Left(strOut, Len(strOut) - 1)
End Function

You can then use it anywhere with a syntax like: InsertChar([Your Field or Value],"-")


Regards,

Duane




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of saigonf7q5@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Friday, January 20, 2017 1:59 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] string functions
 


I use a series of string functions (see below) to change the look of a column of data from this “ 1234567-8” to this “1-2-3-4-5-6-7-8”

 

Left([PrtNum],1)+"-" & Mid([PrtNum],2,1)+"-" & Mid([PrtNum],3,1)+"-" & Mid([PrtNum],4,1)+"-" & Mid([PrtNum],5,1)+"-" & Mid([PrtNum],6,1)+"-" & Right([PrtNum],1) & Right([PrtNum],2)

 

It works so far. What if the number of digits of the rows are not the same? e.g.  some rows are 8 digits, some are 5, 6 or 7.  What is the better or smart way to solve this problem?

 

Thank you

 

Phucon



__._,_.___

Posted by: Duane Hookom <duanehookom@hotmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar