Access 2002, SP3
I have a crosstab query displaying various email addresses for parents/guardians of each student. The columns are based on the relationship to the student: Mother, Father, StepMother, StepFather, FosterMother, FosterFather, Guardian, etc. What I want to achieve in another query is to pull out one email address for each student. If there is no email address for Mother, then I want the one for Father. If there is no email address for Mother or Father then I want the one for StepMother. If there is no email address for Mother, Father, or StepMother then I want the one for StepFather, etc. What expression would I use to achieve that result?
Query Based on Crosstab Query
-
- StarLounger
- Posts: 72
- Joined: 08 Mar 2010, 13:05
- Location: Manassas, VA
-
- Administrator
- Posts: 78626
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Query Based on Crosstab Query
Try:
Email: Nz([Mother],Nz([Father],Nz([StepMother],Nz([StepFather],Nz([FosterMother],Nz([FosterFather],[Guardian]))))))
Make sure that the number of closing parentheses at the end is equal to the number of opening parentheses after the Nz's.
Email: Nz([Mother],Nz([Father],Nz([StepMother],Nz([StepFather],Nz([FosterMother],Nz([FosterFather],[Guardian]))))))
Make sure that the number of closing parentheses at the end is equal to the number of opening parentheses after the Nz's.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Query Based on Crosstab Query
I think it would be easier to add a field (or a whole table if need be) that ranks the types of email addresses with a number, then just use a grouping query to find the address with the minimum rank for each person.
1 Mother
2 Father
3 Step Mother
etc
1 Mother
2 Father
3 Step Mother
etc
Regards
John
John
-
- StarLounger
- Posts: 72
- Joined: 08 Mar 2010, 13:05
- Location: Manassas, VA
Re: Query Based on Crosstab Query
Thank you very much Hans. Your solution worked perfectly.
I will try out the solution from JohnH as well. It always helps to know more than one way to accomplish the same thing.
I will try out the solution from JohnH as well. It always helps to know more than one way to accomplish the same thing.