Solved

Parse a String Multiple Times

Posted on 2013-06-20
3
323 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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 …

777 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