Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to combine duplicate values into one field

Posted on 2011-03-14
3
Medium Priority
?
333 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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

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.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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 …

715 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