Solved

Concatenate records with same data across two fields

Posted on 2007-11-19
2
1,207 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check a field in Access on a Timer 1 28
Access syntax 1 32
Access query error 3 22
SQL Server Compression Decision 5 37
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

679 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