?
Solved

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

Posted on 2013-01-02
7
Medium Priority
?
495 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 40

Expert Comment

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

Accepted Solution

by:
Dale Fye earned 2000 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

752 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