Solved

Need to combine duplicate values into one field

Posted on 2011-03-14
3
323 Views
Last Modified: 2012-06-27
Access 2003

vba routine needed:

I have a table with 2 fields:

I need a new table or query to show th results below:



tblParentChild
fldParent -text
fldChild - text

fldParent      fldChild
D0001      2XKT1
D0001      2XKT2
D0001      2XKT6
D0001      2XKT5
D0001      2XKT4
D0001      2XKT3
D0002      2XKR7
D0002      2XKR8
D0002      2XKR6
D0002      2XKR5
D0002      2XKR4
D0002      2XKR9

I need it to look like this
fldParent                     fldChild
D0001            2XKT1 : 2XKT2 : 2XKT6 : 2XKT5 : 2XKT4 : 2XKT3
D0002            2XKR7 : 2XKR6 : 2XKR5 : 2XKR4 : 2XKR9



Thanks
fordraiders

parentchild.png
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35133592
see the function ConcatThem and the query in this similar thread

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_26833591.html?#a34933741

download the sample db
0
 
LVL 12

Accepted Solution

by:
ErezMor earned 500 total points
ID: 35133630
Sub x1()
Dim rs As New ADODB.Recordset
Dim LastParent As String, strChildren As String

rs.Open "Select * From table1 Order By fldParent", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
While Not rs.EOF
    If LastParent <> rs!fldParent Then
        If LastParent <> "" Then
            DoCmd.RunSQL "Insert Into Table2 (fldParent, frlChild) Values('" & LastParent & "','" & Left(strChildren, Len(strChildren) - 3) & "');"
        End If
        LastParent = rs!fldParent
        strChildren = rs!fldChild & " : "
    Else
        strChildren = strChildren & rs!fldChild & " : "
    End If
    rs.MoveNext
Wend
rs.Close
Set rs = Nothing
End Sub
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 35134225
perfect Thanks !  erezmor
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question