Solved

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

Posted on 2013-01-02
7
483 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 39

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 39

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now