Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

Need to combine duplicate values into one field

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
Fordraiders
Asked:
Fordraiders
1 Solution
 
Rey Obrero (Capricorn1)Commented:
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
 
ErezMorCommented:
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
 
FordraidersAuthor Commented:
perfect Thanks !  erezmor
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now