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
3 3690
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.
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. -
Private Sub btnParse_Click()
-
-
Dim dbsParse As Database
-
Dim rstParse As Recordset
-
Dim intCount As Integer
-
Dim intRecord As Integer
-
Dim varHistRev As Variant
-
Dim varMOrder As Variant
-
Dim varHistNotes As Variant
-
Dim varHistDate As Variant
-
Dim intCurrent As Integer
-
Dim strHistRev As String
-
Dim strMOrder As String
-
Dim strHistNotes As String
-
Dim strHistDate As String
-
-
strHistRev = ""
-
strMOrder = ""
-
strHistNotes = ""
-
strHistDate = ""
-
Set dbsParse = CurrentDb
-
Set rstParse = dbsParse.OpenRecordset("tblHistory")
-
-
rstParse.MoveLast
-
rstParse.MoveFirst
-
Do Until rstParse.EOF
-
varHistRev = Split(rstParse![HistRev], ";")
-
varMOrder = Split(rstParse![MOrder], ";")
-
varHistNotes = Split(rstParse![HistNotes], ";")
-
varHistDate = Split(rstParse![HistDate], ";")
-
intCurrent = 0
-
Do Until intCurrent = UBound(varHistRev) + 1
-
strHistRev = varHistRev(intCurrent)
-
If intCurrent < (UBound(varMOrder) + 1) Then strMOrder = varMOrder(intCurrent)
-
If intCurrent < (UBound(varHistNotes) + 1) Then strHistNotes = varHistNotes(intCurrent)
-
If intCurrent < (UBound(varHistDate) + 1) Then strHistDate = varHistDate(intCurrent)
-
intCurrent = intCurrent + 1
-
-
dbsParse.Execute " INSERT INTO tblDestination " _
-
& "(HistRev, MOrder, HistNotes, HistDate) VALUES " _
-
& "('" & strHistRev & "','" & strMOrder & "','" & strHistNotes & "','" & strHistDate & "');"
-
Loop
-
rstParse.MoveNext
-
Loop
-
-
Set rstParse = Nothing
-
dbsParse.Close
-
-
End Sub
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).
Sign in to post your reply or Sign up for a free account.
Similar topics
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,...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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--...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |