473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

parse semicolon delimited table

MS Access 2003

I have a table called tblHistory with the following fields...
HistRev MOrder HistNotes HistDate
with the below data rows. It is semicolon delimited.
I need to parse the records to a new table called tblDestination

HistRev
1;2;3
1;2

MOrder
abc123
xz123

HistNotes
Save;Submit;Cancel
Initiate;Save

HistDate
2009-06-22 01:41:16 PM;2010-06-23 02:31:16 PM;2010-08-22 04:41:16 PM
2010-06-23 02:31:16 PM;2010-08-22 04:41:16 PM


I need the new field records in tblDestination to look like


HistRev
1
2
3
1
2

MOrder
abc123
abc123
abc123
xz123
xz123

HistNotes
Save
Submit
Cancel
Initiate
Save

HistDate
2009-06-22 01:41:16 PM
2010-06-23 02:31:16 PM
2010-08-22 04:41:16 PM
2010-06-23 02:31:16 PM
2010-08-22 04:41:16 PM


Please, please help
Jul 21 '11 #1
3 3690
Rabbit
12,516 Expert Mod 8TB
It would probably be easiest to use VBA.
1) Step through the recordset.
2) Split() out the fields.
3) Loop through the split() result and insert records into the new table.
Jul 21 '11 #2
gnawoncents
214 100+
I was working on the same concept and came up with the code listed below. It takes into consideration the fact that MOrder only has one entry per field. Also, it is based on the assumption that the HistRev field will always have one entry per parsed record. All you would need to add is some way to ensure you don't copy over the same records again if this is not a one-time transfer.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnParse_Click()
  2.  
  3. Dim dbsParse As Database
  4. Dim rstParse As Recordset
  5. Dim intCount As Integer
  6. Dim intRecord As Integer
  7. Dim varHistRev As Variant
  8. Dim varMOrder As Variant
  9. Dim varHistNotes As Variant
  10. Dim varHistDate As Variant
  11. Dim intCurrent As Integer
  12. Dim strHistRev As String
  13. Dim strMOrder As String
  14. Dim strHistNotes As String
  15. Dim strHistDate As String
  16.  
  17. strHistRev = ""
  18. strMOrder = ""
  19. strHistNotes = ""
  20. strHistDate = ""
  21. Set dbsParse = CurrentDb
  22. Set rstParse = dbsParse.OpenRecordset("tblHistory")
  23.  
  24. rstParse.MoveLast
  25. rstParse.MoveFirst
  26. Do Until rstParse.EOF
  27.     varHistRev = Split(rstParse![HistRev], ";")
  28.     varMOrder = Split(rstParse![MOrder], ";")
  29.     varHistNotes = Split(rstParse![HistNotes], ";")
  30.     varHistDate = Split(rstParse![HistDate], ";")
  31.     intCurrent = 0
  32.     Do Until intCurrent = UBound(varHistRev) + 1
  33.         strHistRev = varHistRev(intCurrent)
  34.         If intCurrent < (UBound(varMOrder) + 1) Then strMOrder = varMOrder(intCurrent)
  35.         If intCurrent < (UBound(varHistNotes) + 1) Then strHistNotes = varHistNotes(intCurrent)
  36.         If intCurrent < (UBound(varHistDate) + 1) Then strHistDate = varHistDate(intCurrent)
  37.         intCurrent = intCurrent + 1
  38.  
  39.         dbsParse.Execute " INSERT INTO tblDestination " _
  40.         & "(HistRev, MOrder, HistNotes, HistDate) VALUES " _
  41.         & "('" & strHistRev & "','" & strMOrder & "','" & strHistNotes & "','" & strHistDate & "');"
  42.     Loop
  43. rstParse.MoveNext
  44. Loop
  45.  
  46. Set rstParse = Nothing
  47. dbsParse.Close
  48.  
  49. End Sub
Jul 21 '11 #3
NeoPa
32,556 Expert Mod 16PB
Nice work gnawoncents.

The OP may need to determine if [HistRev] is numeric or not and change the SQL accordingly. This is possibly also true for [HistDate], but for Date/Time rather than numeric. [MOrder] appears to be single items only, so that may need a little minor tweaking. rstParse should probably be closed prior to setting to Nothing, and dbsParse would never be closed (as it's a pointer to the current database), but she can presumably sort that out now she has a pretty full template solution to work from. Considering you were working on a database in your head that's not bad going (All the points are pretty minor and usually get picked up when testing anyway, when it's hands-on).
Jul 22 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: monte | last post by:
Hello, I need to parse a tilde delimited file and output it to a tabbed delimited file. Example file example.txt data1~data2~data3~data4 data5~data6~data7~data8 I need to extract data2,...
6
by: wk | last post by:
i have a <table></table> ...and the have a string with the html that will create the table rows, columsn etc....perhaps <tr><td>a row</td></tr>. this string comes dynamically from a source and...
3
by: Ben | last post by:
Hi all - I am having a bit of trouble and thought maybe someone in this group could shed some light. Here's the skinny... I am creating an automated process to import a bunch of text files...
25
by: electrixnow | last post by:
in MS VC++ Express I need to know how to get from one comma delimited text string to many strings. from this: main_string = "onE,Two,Three , fouR,five, six " to these: string1 =...
5
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML...
2
by: Jacob.Bruxer | last post by:
Hi everyone, I'm having trouble opening space delimited textfiles in Excel from Visual Basic.net. I'm able to control, open and modify Excel files from Visual Basic, so my Excel reference seems...
0
by: =?Utf-8?B?VmluY3k=?= | last post by:
Hi I am using Interop.Excel Com object. When I save the file as CSV, its separated as Comma delimited. But I want the user to specify the delimiter and save the file in the user specified...
4
by: xzzy | last post by:
I have hit a wall with not being able to enumerate the items collection in a table row. given: <table runat=server id=table1> <tr> <td id=AAA>HowToReferenceThisValue</td> etc...
4
by: JovieUrbano | last post by:
I have a question. I am working on something based on the information I got from this forum. I am using the sample I found and modifying it a little to get the results I want.. --TABLE--...
6
by: artemetis | last post by:
Howdy! I've got a table with some contact information. uid, emailaddy, username The user name data is inconsistent.... some names are as Bill Jones, some are B.Jones and some are the email...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.