parse string to multi records

L

LGarcia

Hi all,
I have a table with 2 fields. Field1 is the primary key. Field2 is a string
of text separated by commas. I need to parse this to create a multi record.
The data resembles this:
Car | blue, green, black, gray
bike | red
boat | blue, red

I need it to be multi-record:
car | blue
car | green
car | red
bike | red
boat | blue
boat | red

Can anyone help?
Thanks,
LGarcia
 
S

Stefan Hoffmann

hi,
I have a table with 2 fields. Field1 is the primary key. Field2 is a string
of text separated by commas. I need to parse this to create a multi record.
The data resembles this:
Car | blue, green, black, gray
bike | red
boat | blue, red
Use Split() to parse your field and a VBA loop over your data, e.g.
something like this:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Dim i As Long
Dim s() As String

Set db = CurrentDb
Set rs = db.OpenRecordset("yourTable", dbOpenSnapshot)
Do While Not rs.Eof
s() = Split(rs![yourField], ",")
If UBound(s) > 0 Then
For i = 0 To UBound(s)
db.Execute "INSERT INTO yourTable " & _
"VALUES ('" & rs![yourField1] & "', '" & s(i) & "')"
Next i
End If
rs.MoveNext
Loop


mfG
--> stefan <--
 
L

LGarcia

Worked!
Thanks!!!!
LGarcia

Stefan Hoffmann said:
hi,
I have a table with 2 fields. Field1 is the primary key. Field2 is a
string of text separated by commas. I need to parse this to create a
multi record.
The data resembles this:
Car | blue, green, black, gray
bike | red
boat | blue, red
Use Split() to parse your field and a VBA loop over your data, e.g.
something like this:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Dim i As Long
Dim s() As String

Set db = CurrentDb
Set rs = db.OpenRecordset("yourTable", dbOpenSnapshot)
Do While Not rs.Eof
s() = Split(rs![yourField], ",")
If UBound(s) > 0 Then
For i = 0 To UBound(s)
db.Execute "INSERT INTO yourTable " & _
"VALUES ('" & rs![yourField1] & "', '" & s(i) & "')"
Next i
End If
rs.MoveNext
Loop


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top