VB Access 2010 Parse Delimited Row to Column
Function splitWords(ByVal strLine)
Dim ParsedStrLine() As String
ParsedStrLine = Split(strLine, ", ")
For i = LBound(ParsedStrLine) To UBound(ParsedStrLine)
splitWords = 开发者_运维问答ParsedStrLine(i)
Next
End Function
I know next to nothing about VB. I am trying to write a function that takes in a csv field and appends back to the same table in a different column.
THIS someTable: col_1 col_2 a x, y, z TO THIS someTable: col_1 col_2 a x, y, z x y z
Let me know if you need anymore information.
For just one row:
ParsedStrLine = Split(strLine, ", ")
For i = LBound(ParsedStrLine) To UBound(ParsedStrLine)
splitWords = ParsedStrLine(i)
CurrentDB.Execute "INSERT INTO tbl (Col1) VALUES ('" & splitWords & "'")
Next
But you may wish to work with the whole recordset.
Dim db As Database
Dim rs As Recordset
Dim rsAdd As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Table1 WHERE Col_2 Is Not Null")
Set rsAdd = db.OpenRecordset("Table1")
Do While Not rs.EOF
ary = Split(rs!col_2, ", ")
For i = 0 To UBound(ary)
rsAdd.AddNew
rsAdd!col_1 = ary(i)
rsAdd.Update
Next
rs.MoveNext
Loop
精彩评论