Link to home
Start Free TrialLog in
Avatar of Gary Samuels
Gary SamuelsFlag for United States of America

asked on

Merging an unknow number of records

I have a mastermember table in which each record represents a family. The key field is [membershipID]. I have a members table which represents individual people. The key field is [memberID]. Any number of people may represent a family. I need to develop a table which contains a single row for each family and each member of the family needs to be included.

I need this because I've been ask to produce a spreadsheet containing all family members which can be used in a mail merge.

Creating a query to select the [head_of_house] is simple but how do you select the other family members when there may be none, one or any number?

Using the members table I have the following fields.
membershipID ; used to group the family
memberID ; to identify each member of the family
membertype ; head, spouse, son, daughter

I know there needs to be a loop involved by I don't know how to execute it.
Loop through all [membertype = son] where [membershipID = head.membershipID] ?

Any suggestion on a concept, a direction to start?
Attached is a sample database and spreadsheet.
family.accdb
family.xlsx
Avatar of PatHartman
PatHartman
Flag of United States of America image

Here is a function written by Allen Browne that will do the concatenation for you.

http://allenbrowne.com/func-concat.html
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary Samuels

ASKER

As instructed I inserted a new module which was named Module 2. I also added the function to the end of Module 1, and the Global Module.

I tried it but all I could get was "Undefined function 'ConcatRelated' in function".
The procedure needs to be in ONE and ONLY ONE module.  That is because the procedure MUST be public in order to be referenced from a query.  If multiple modules contain the same procedure name, you will get compile errors.

So,
1. Put the procedure  in ONE module.
2. Make sure the procedure is defined as Public.
3. Make sure everything compiles.
4. Make sure that there are no typos.
It Worked.