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
Solved

Concatenate records with same data across two fields

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 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