Hi,
I still don't know if it can be done with pure SQL, but i got it working
without VBA code which loops through records. (Not to mention the time lost
for opening and closing the recordset.)
The trick is using two queries and a bit of VBA code. It works faster than
looping through records in VBA.
1. The base query GROUPS some Recordkey and GROUPS the Textfield you want to
populate. In a 3th column a calculated textfield as EXPRESSION calls a
public function fnPopulateTextfield which takes to params (Recordkey and
Textfield).
RecID
GROUP BY
Textfield
GROUP BY
PopulatedText: fnPopulateTextfield([RecID];[Textfield])
EXPRESSION
The second column is needed because without it the query does not recognizes
that Textfield is part of a statistic function! The side effect is that it
will group on every Textfield, but the final query will correct this!
2. The finishing query based on the above query GROUPS again on the
Recordkey and takes the LAST record of the calculated populated textfield.
RecID
GROUP BY
PopulatedText
LAST
3. The function fnPopulateTextfield uses two STATIC vars (long and string).
every time it sees a different recordkey it reinitializes the STATIC vars
(Long var gets new recordkey and the String var gets empty). Next it adds
the Textfield to the STATIC string var seperated by comma and then returns
the STATIC string var.
Lets say you have a table like the next one :
RecID SomeTextfieldYouWantToPopulate
1 Cat
1 Dog
2 Fish
3 Lion
3 Birth
3 Snake
4 Dog
4 Crock
4 Hyena
4 Fish
After the base query you will get:
RecID PopulatedTextfield
1 Cat
1 Cat, Dog
2 Fish
3 Lion
3 Lion, Birth
3 Lion, Birth, Snake
4 Dog
4 Dog, Crock
4 Dog, Crock, Hyena
4 Dog, Crock, Hyena, Fish
What the f*#%! Don't worry after the final query you will get:
1 Cat, Dog
2 Fish
3 Lion, Birth, Snake
4 Dog, Crock, Hyena, Fish
Voila!
My own code was too complex to show the basic principle, sorry!
Good luck and if you believe hard enough it will happen!
Sidney.
"Pieter Linden" <pietlinden@hotmail.com> schreef in bericht
news:bf31e41b.0309301750.7a6ce11f@posting.google.c om...[color=blue]
> Don't think pure SQL will do it. You have to use code. There's code for[/color]
it here:[color=blue]
>
>
http://www.mvps.org/access/modules/mdl0004.htm
>
> "Return a concatenated list of sub-record values"[/color]