Solved

Concatenate records with same data across two fields

Posted on 2007-11-19
2
1,204 Views
Last Modified: 2010-04-21
Hi
I am using MS ACCESS 2003 on XP Pro and was hoping you could help me.

I have a query that displays duplicate records based on two fields. I would like concatenate all dupicate data into one record. For example (field names first row):
F1, F2, F3
A, 2, Church
A, 2, Library
B, 1, Station
B, 1, <Null>
B, 1, Post Office
C, 5, Hall

I would like to concatenate as follows:

F1, F2, F3
A, 2, Church Library
B, 1, Station <Null> Post Office
C, 5, Hall

Ideally I would like the solution in SQL but if its best to use vba please supply basis if you can.

Thanks
0
Comment
Question by:pxj05
2 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 20313359
You could try this with a vba func
eg

public function GetF3(byval F1 as String, byval F2 as integer)

    dim rs as dao.recordset
    dim sF3 as string

    set rs=currentdb.openrecordset("SELECT F3 FROM mytable WHERE F1 = '" & f1 & "' and f2 = " & f2)
    do while rs.eof = false
        sF3 = sF3 & " " & rs!F3
        rs.movenext
    loop
    rs.close
    set rs=nothing

    GetF3 = trim$(sF3)
end function


save it then in a query do this

select f1, f2, GetF3(f1, f2) as F3Cat
from mytable
group by f1, f2
0
 

Author Closing Comment

by:pxj05
ID: 31409957
x e lent - I can now use this as a basis. thank you very much
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now