Concatenate Related Records

GendoPose

Registered User.
Local time
Today, 23:55
Joined
Nov 18, 2013
Messages
175
Hi All,

In my query, I have several results that relate to the same PK overall, and I'd like to concatenate these records into one expression/one field in a form.

Currently my query looks like this;

2n8dix5.png


As you can see, the BandPK/BandFK are repeated where the GenreFK/GenrePK are different. What I'd like to do is concatenate the column named Genres into one field so the BandFK/PK isn't repeated.

If you need any more info/screenshots, please ask.

Thanks
 
I think you may need to Normalize your tables, but we don't know anything about your "business".
Can you show us a jpg of your relationships window?

You might also want to show us the SQL view of your Query.
 
I think you may need to Normalize your tables, but we don't know anything about your "business".
Can you show us a jpg of your relationships window?

You might also want to show us the SQL view of your Query.

As far as I'm aware my tables are properly normalised, I had some help on that beforehand.

Here is the SQL for the query;

Code:
SELECT tblBands.BandPK, tblBandMembers.BandFK, tblBands.BandName, tblBandGenres.GenreFK, tblGenres.GenrePK, tblGenres.Genres, tblUsers.UserPK, tblBandMembers.UserFK, tblUsers.FName, tblUsers.LName, tblBandMembers.MemberDateFrom, tblBandMembers.MemberDateTo
FROM tblUsers INNER JOIN (tblGenres INNER JOIN ((tblBands INNER JOIN tblBandGenres ON tblBands.BandPK = tblBandGenres.BandFK) INNER JOIN tblBandMembers ON tblBands.BandPK = tblBandMembers.BandFK) ON tblGenres.GenrePK = tblBandGenres.GenreFK) ON tblUsers.UserPK = tblBandMembers.UserFK
WHERE (((tblBandMembers.MemberDateTo) Is Null));

Here are the table relationships;

15cy6o1.png
 
Ok, I agree with the Normalization.

What exactly is the purpose of the query (I guess it's recordsource for form). Why do you need all the PK FK fields?
 
Ok, I agree with the Normalization.

What exactly is the purpose of the query (I guess it's recordsource for form). Why do you need all the PK FK fields?

Yeah the query is to show Current members with the bands, genres, instruments etc, which is then used in a sub form for each User.

The PK and FK fields are so I can find the related records on the main form, but in the form it looks similar to the repeated results in the query;

29pp4qh.png
 
Not sure I can help, not knowing how you tried to use it or what went wrong. ;)
 
Not sure I can help, not knowing how you tried to use it or what went wrong. ;)

Well the underlying query looks like this so far;

ebcxvo.png


The form looks like this;

21n0b40.png


And the control source for the text box looks like this;

23lxsm0.png


I've gone through the example on the website so many times and tried googling around for any problems other people have had and I can't get it at all, the results of the form just look like this;

29uu1qh.png


:confused:
 
See a difference between yours and Allen's?

=ConcatRelated("OrderDate", "tblOrders", "CompanyID = " & [CompanyID])

Hint, the quotes aren't optional.
 
See a difference between yours and Allen's?

=ConcatRelated("OrderDate", "tblOrders", "CompanyID = " & [CompanyID])

Hint, the quotes aren't optional.

Ok so I've got it half fixed now, I've managed to concatenate the results, but it's come out like this;

9qeo8n.png


My control source looks like this;

14v4r3n.png
 
Edit the RecordSource of the Form to a GroupBy Query?
 
Edit the RecordSource of the Form to a GroupBy Query?

How do I change the Query to a GroupBy? I can't find any options for it, so would I have to recreate the Query in a different way?

EDIT; never mind, I've found that but it's not changed it how I was hoping
 
So your query which once was.
Code:
SELECT someBandName, someGenere FROM theTable;
is now,
Code:
SELECT someBandName, someGenere FROM theTable
GROUP BY someBandName, someGenere;
and it is not working? :eek:
 
So your query which once was.
Code:
SELECT someBandName, someGenere FROM theTable;
is now,
Code:
SELECT someBandName, someGenere FROM theTable
GROUP BY someBandName, someGenere;
and it is not working? :eek:

Nope..

My SQL is currently this;

Code:
SELECT tblBands.BandPK, tblBandMembers.BandFK, tblBands.BandName, tblBandGenres.GenreFK, tblGenres.GenrePK, First(tblGenres.Genres) AS FirstOfGenres, tblBandMembers.UserFK, tblUsers.UserPK, tblUsers.FName, tblUsers.LName, tblBandMembers.MemberDateFrom, tblBandMembers.MemberDateTo
FROM tblUsers INNER JOIN (tblGenres INNER JOIN ((tblBands INNER JOIN tblBandGenres ON tblBands.BandPK = tblBandGenres.BandFK) INNER JOIN tblBandMembers ON tblBands.BandPK = tblBandMembers.BandFK) ON tblGenres.GenrePK = tblBandGenres.GenreFK) ON tblUsers.UserPK = tblBandMembers.UserFK
GROUP BY tblBands.BandPK, tblBandMembers.BandFK, tblBands.BandName, tblBandGenres.GenreFK, tblGenres.GenrePK, tblBandMembers.UserFK, tblUsers.UserPK, tblUsers.FName, tblUsers.LName, tblBandMembers.MemberDateFrom, tblBandMembers.MemberDateTo
HAVING (((tblBandMembers.MemberDateTo) Is Null));

and the results in the subform with concat text box look like this;

2ecn66s.png
 
I can only see three fields in the Form, so if you use only those three fields as the actual Recordsource of the Form, then it should get you working?
 
I can only see three fields in the Form, so if you use only those three fields as the actual Recordsource of the Form, then it should get you working?

Even with just those 3 fields in, it has the exact same results :confused:
 

Users who are viewing this thread

Back
Top Bottom