Re: extract items from list in single field
- From: "Wayne Morgan" <comprev_gothroughthenewsgroup@xxxxxxxxxxx>
- Date: Thu, 19 Jan 2006 15:39:49 -0600
Try using the Split() function to change the delimited string into an array.
You would then loop through the members of the array and write one record to
the table for each member.
Example:
Public Sub TestSplit()
Dim db As DAO.Database, rstRead As DAO.Recordset, rstWrite As DAO.Recordset
Dim strResult() As String, i As Long
Set db = CurrentDb
Set rstRead = db.OpenRecordset("TableName", dbOpenSnapshot)
Set rstWrite = db.OpenRecordset("DestinationTableName", dbOpenDynaset)
If Not (rstRead.BOF And rstRead.EOF) Then
'If both are true, no records were in the table
rstRead.MoveFirst
Do Until rstRead.EOF
strResult() = Split(CStr(rstRead!ItemList), ",")
For i = LBound(strResult) To UBound(strResult)
With rstWrite
.AddNew
!ID = rstRead!ID
!ItemList = strResult(i)
.Update
End With
Next i
rstRead.MoveNext
Loop
rstRead.Close
rstWrite.Close
Set rstRead = Nothing
Set rstWrite = Nothing
Set db = Nothing
End Sub
--
Wayne Morgan
MS Access MVP
"Pendragon" <Pendragon@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:18B9A8F6-93BF-46FB-BE1B-FAAC1B739A19@xxxxxxxxxxxxxxxx
>I have a table with fields IndividualID, ItemList. ItemList is a single
>text
> field that has items separated by a comma (e.g., "apple, orange, lemon,
> lime").
>
> I need to create a table that lists each item singly on a record.
>
> ID = 101
> ItemList = Apple, Orange, Lemon, Lime
>
> translates to
>
> 101 Apple
> 101 Orange
> 101 Lemon
> 101 Lime
>
> and so forth through the remaining records.
>
> Can anyone point me to sample code that I can modify or play around with?
> I'm not new to programming concepts and have a good idea of the necessary
> algorithm, but lack the experience to set it out in VBA.
>
> Any help is truly appreciated.
>
> Ross
.
- Prev by Date: Re: splitting address from one field to two
- Next by Date: Re: extract items from list in single field
- Previous by thread: Re: splitting address from one field to two
- Next by thread: Re: extract items from list in single field
- Index(es):
Relevant Pages
|