sistemalan
Registered User.
- Local time
- Today, 05:35
- Joined
- Jun 19, 2009
- Messages
- 77
My database stores details of children taking part in a music project.
I want to create a query which I can use for a mail merge to write to all the families. Some children are from the same families. I don't want more than one letter to go to the same family, but in the letter I want to be able to refer to each child.
There are two tables: T_Adults & T_Children, which are related in a One to Many Relationship by the common field AdultID.
So far I have the below query which will show all children who attend.
What I want to be able to do is as follows:
1 - Where two or more records share the same parent (i.e. if the field T_Children.AdultID is the same for both records) only show the record for the oldest child (calculated from dates of birth).
The query should now show a) children with no siblings and b)The oldest children from families with more than one child taking part.
2 - Create a dynamic field on the records of children with siblings' names which records their siblings' first names. If there is one sibling it should read (for instance) "& John", if two siblings it should read ", Toby & John", if three it should read ", Sam, Toby and John", etc... This is so I can write letters and say things like "We hope that Jim, Sam, Toby and John can join us next week".
I'd be much obliged if someone could point me in the right direction with this.
Thanks in advance!
Alan
I want to create a query which I can use for a mail merge to write to all the families. Some children are from the same families. I don't want more than one letter to go to the same family, but in the letter I want to be able to refer to each child.
There are two tables: T_Adults & T_Children, which are related in a One to Many Relationship by the common field AdultID.
So far I have the below query which will show all children who attend.
Code:
SELECT T_Children.FirstName, T_Children.Surname, T_Children.DateOfBirth, T_Children.AdultID, T_Adults.AdultName, T_Adults.Address1, T_Adults.Address2, T_Adults.PostCode, T_Children.SignedUpForAfterSchool
FROM T_Adults RIGHT JOIN T_Children ON T_Adults.AdultID = T_Children.GuardianID
WHERE (((T_Children.SignedUpForAfterSchool)=True));
1 - Where two or more records share the same parent (i.e. if the field T_Children.AdultID is the same for both records) only show the record for the oldest child (calculated from dates of birth).
The query should now show a) children with no siblings and b)The oldest children from families with more than one child taking part.
2 - Create a dynamic field on the records of children with siblings' names which records their siblings' first names. If there is one sibling it should read (for instance) "& John", if two siblings it should read ", Toby & John", if three it should read ", Sam, Toby and John", etc... This is so I can write letters and say things like "We hope that Jim, Sam, Toby and John can join us next week".
I'd be much obliged if someone could point me in the right direction with this.
Thanks in advance!
Alan