Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access Expression to parse a delimited string

Posted on 2012-12-28
10
Medium Priority
?
555 Views
Last Modified: 2012-12-31
I have an Access table containing a pipe-delimited string in a single field. The string looks something like this...

Fieldname = fullText
value1|other value2|some other value3|yet another value4|and a final value5|

I need help writing an Access Expression which will take the string above and break it into separate fields like this...

Field       Value
value1    value1
value2    other value2
value3    some other value3
value4    yet another value4
value5    and a final value5

Can you help me with this? (I'm more familiar with expressions than VB but will accept a VB approach if you can walk me through how to implement.)
0
Comment
Question by:P-Daddy
[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
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38728191
Will the string always have the same amount of delimiters?

What about "Blanks"?: SomeText||SomeMoreText
Is this string field in the same table that "target" fields are in?
0
 

Author Comment

by:P-Daddy
ID: 38728643
Answers:
1) Yes, the string will always have the same number of delimiters
2) Yes, there may be blanks between delimiters, like ||
3) Yes, the string field is in the same table as the target fields but could be separated if necessary.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38728691
So in your example are you saying you would end up with a table having 5 columns with each delimited string in each field?  If so, couldn't you just import the delimited file straight in to the table?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38728698
<2) Yes, there may be blanks between delimiters, like ||>
So then what do you want to happen in this case...?

I think IrogSinta has your solution here.
0
 

Author Comment

by:P-Daddy
ID: 38728702
I wish I could, but the string is quite long and the whole string is actually not available for me to import. It is stored broken up into 12 132 character fields in its original table. What I've done so far is to concatenate all this so at least I have the full string in one field. Now I need your help in parsing the string at each pipe. Easy to do in Excel, I'm just not familiar with how to write this expression in Access. Thanks in advance!
0
 

Author Comment

by:P-Daddy
ID: 38728704
To answer the other comment above if there's a blank between pipe separators I would expect a null value to be written in that field. Does that make sense?
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38728724
Assuming you already have a table you want to store these 5 fields into you could use code similar to this:
Private Sub ParseAString()
    Dim rst As Recordset
    Dim strToParse As String
    Dim arrParsed
    
    strToParse = DLookup("[FieldName]","TableName")  'this is the table that holds your string.
    arrParsed = Split(strToParse, "|")
    
    Set rst = CurrentDb.OpenRecordset("NameOfTable")  'this is the table to store the 5 fields.
    rst.AddNew
    For i = 0 To 4
        rst(i).Value = arrParsed(i)
    Next
    rst.Update
    rst.Close
    Set rst = Nothing
End Sub

Open in new window

Did your table have more than one record to parse?
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1200 total points
ID: 38729041
In a query you can have an expression to retrieve each value/item:

value1: GetFullTextItem([FullText], 0)
value2: GetFullTextItem([FullText], 1)
value3: GetFullTextItem([FullText], 2)
value4: GetFullTextItem([FullText], 3)
value5: GetFullTextItem([FullText], 4)

using this function:

Public Function GetFullTextItem( _
  ByVal strFullText As String, _
  ByVal intItem As Integer) As String
 
  On Error Resume Next
  GetFullTextItem = Split(strFullText, "|")(intItem)

End Function

/gustav
0
 

Author Closing Comment

by:P-Daddy
ID: 38731721
I awarded this as the solution of choice because it was the most elegant solution of the two with the least amount of code and I could perform both concatenate and parse steps in the same query. However, I said I was a novice and your solution left me having to do additional research on how to create functions and call them from my query and I had to find out how to replace the [FullText] to get this to work. I know that's just my being a newbie, but you could have easily added some additional help to your solution.

Nevertheless, I could not have gotten past this without you. Thank you!
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 38732365
You are welcome!
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

722 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