Solved

Access Code to parse a delimited string in a field in a table

Posted on 2013-01-02
7
493 Views
Last Modified: 2013-01-02
I need help with code to parse a string into a column of values.  For example the string looks like this 1234_4536_4526_7896.  I need it in a table with c olumn
1234
4536
4526
7896

I need to be able to put run the code without specifying how many values are in the delimited field.  The values can vary from one to 20 or more.
0
Comment
Question by:LBOYLE4
[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
  • 2
  • 2
  • +1
7 Comments
 
LVL 14

Expert Comment

by:theruck
ID: 38737632
get the values to any text editor and replace_with newline. then copy the data wherever you want. a good texteditor is textpad you would do it there in 10 seconds
0
 

Author Comment

by:LBOYLE4
ID: 38737643
I will need to map them to a parent record.  So I need to parse them so I can write a query for a second piece of this project.  So my ultimate goal would to be able to parse the records into a table like this

Column 1  Parse row
Parent1     1234
Parent1      2345
Parent1     4563
Parent2      1123
Parent2       44563
0
 
LVL 40

Expert Comment

by:als315
ID: 38737654
You can do it in VBA. Use split function to separate records, open your table with openrecordset, add records. If you upload sample DB with this table and resulting table (empty), you can get exact code
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:als315
ID: 38737699
Look at sample
DBparse.accdb
0
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 38737709
You need a subroutine or function, something like:
Private Sub ParseText

    Dim strSQL as string
    Dim rsSource as DAO.Recordset, rsDest as DAO.Recordset
    Dim db as DAO.Database
    Dim strArray() as string, intLoop as integer

    'this is the table you want the data to go into
    strSQL = "SELECT RowID, [Parsed] FROM yourTable" 
    set db = Currentdb
    set rsDest = db.OpenRecordset(strSQL)

    strSQL = "SELECT ID, [ColumnName] FROM yourSourceTable " _
                & "WHERE [ColumnName] IS NOT NULL"
    set rsSource = db.openrecordset(strSQL)
    While not rsSource.EOF
         strArray() = split(rsSource![ColumnName], "_")
         For intLoop = lbound(strArray()) to UBound(strArray())
             rsDest.AddNew
             rsDest!RowID = rsSource!ID
             rsDest!Parsed = strArray(intLoop)
             rsDest.Update
         Next
         rsSource.MoveNext
    Wend

    rsSource.Close
    set rsSource = nothing
    rsDest.Close
    set rsDest = Nothing

End Sub

Open in new window

You will need to replace the column and table names I have provided, but this should give you a starting place.
0
 

Author Comment

by:LBOYLE4
ID: 38737926
FYED,
What if i wanted to put the results in a static table.  Would I just replace strSQL with the table name: db.OpenRecordset(tablename)?
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 38737947
That is what this code would do.  You would simply change the SQL used to define rsDest to refer to your table, and use the appropriate field names from that table for the original record # and for the parsed string values.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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