Solved

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

Posted on 2013-01-02
7
490 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
  • 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 47

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 47

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

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!

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

713 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