Solved

Parse a String Multiple Times

Posted on 2013-06-20
3
324 Views
Last Modified: 2013-06-20
Hello,

I have a field that is designed as follows:
          ??/#######/????????/########/???
I would like to parse the field based on the "/".  The field is not alway consistant, so I would like to have the complete string show in the first parse, if the "/" is not available.

I have been tring the Left$ function:
          Left$([Field Name],InStr(2,[Field Name],"/")-1)
This was able to bring in the first part.  Yet it gives me an error of "Func!" if the "/" is not in the string and I have not been successful in tring to retrieve the second portion.

Any help would be  greatly appreciated.
0
Comment
Question by:ammiewinds
3 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 39262609
It's not really clear what your aim is here, but the simple way is to use the split() function.

dim myarray
myarray= split(fieldname, "/")
'first value myarray(0), then myarray(1) etc
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39262637
I use a function (fnParseText) that looks something like:
Public Function fnParseText(ParseWhat as Variant, Element as integer, Optional Delimiter as string = ",") as Variant

    Dim myArray() as string

    myArray = Split(ParseWhat, Delimiter)

    if Element < 0 OR Element > ubound(myArray) + 1 then
         fnParseText = NULL
    Else
         fnParseText = myArray(Element - 1)
    End If

End Function

Open in new window

Then, in your query you would use:

SELECT fnParseText([YourField], 1, "/") as FirstElement
           , fnParseText([YourField], 2, "/") as SecondElement
           , fnParseText([YourField], 3, "/") as ThirdElement
FROM yourTable
0
 

Author Closing Comment

by:ammiewinds
ID: 39263137
Thank you so very much!  Now I'm happy I joined the club.

Jumping up and down!!!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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