Hi. The following query (in blue) does not work properly. If anyone can help me correct it I would be very grateful.
In my database, a RESEARCH record can comprise any number of ADVISORS (linked by ResAdList table) and any number of CONTACTS (linked by ResCoList).
I have a form RESEARCHMANAGE with two combo boxes, SELECTADVISOR and SELECTCONTACT, these boxes return advisor and contact ID numbers respectively.
I want to retrieve research records where CONTACT ID and/or ADISOR ID are as selected by the combo boxes. (I.e. if one of selectcontact or selectadvisor are left null, then the query just returns rsearch records by advisor or by contact respectively.)
The WHERE clause in the query below works correctly.
The problem is that, due to the join properties between tables, research records are not returned by the query in cases where no associated advisors or contacts exist.
Below is a summary of what I require:
If both SELECTADVISOR and SELECTCONTACT are chosen...
- all RESEARCH records where both the ADVISOR and the CONTACT were present.
If SELECTADVISOR only is chosen...
- all RESEARCH records where the ADVISOR was present - for all contacts - even if no contacts at all are listed for the RESEARCH record (the latter part is what does not work).
If SELECTCONTACT only is chosen...
- all RESEARCH records where the CONTACT was present - for all advisors - even if no advisors at all are listed for the RESEARCH record (the latter part is what does not work).
SELECT Research.resID, Research.resSelect, Advisor.adID, Contact.coID
FROM (Research INNER JOIN (Advisor INNER JOIN ResAdList ON Advisor.adID = ResAdList.adID) ON Research.resID = ResAdList.resID) INNER JOIN (Contact INNER JOIN ResCoList ON Contact.coID = ResCoList.coID) ON Research.resID = ResCoList.resID
WHERE (((Advisor.adID) Like IIf(IsNull([Forms]![ResearchManage]![selectadvisor]),'*',[Forms]![ResearchManage]![selectadvisor])) AND ((Contact.coID) Like IIf(IsNull([Forms]![ResearchManage]![selectcontact]),'*',[Forms]![ResearchManage]![selectcontact])));
In my database, a RESEARCH record can comprise any number of ADVISORS (linked by ResAdList table) and any number of CONTACTS (linked by ResCoList).
I have a form RESEARCHMANAGE with two combo boxes, SELECTADVISOR and SELECTCONTACT, these boxes return advisor and contact ID numbers respectively.
I want to retrieve research records where CONTACT ID and/or ADISOR ID are as selected by the combo boxes. (I.e. if one of selectcontact or selectadvisor are left null, then the query just returns rsearch records by advisor or by contact respectively.)
The WHERE clause in the query below works correctly.
The problem is that, due to the join properties between tables, research records are not returned by the query in cases where no associated advisors or contacts exist.
Below is a summary of what I require:
If both SELECTADVISOR and SELECTCONTACT are chosen...
- all RESEARCH records where both the ADVISOR and the CONTACT were present.
If SELECTADVISOR only is chosen...
- all RESEARCH records where the ADVISOR was present - for all contacts - even if no contacts at all are listed for the RESEARCH record (the latter part is what does not work).
If SELECTCONTACT only is chosen...
- all RESEARCH records where the CONTACT was present - for all advisors - even if no advisors at all are listed for the RESEARCH record (the latter part is what does not work).
SELECT Research.resID, Research.resSelect, Advisor.adID, Contact.coID
FROM (Research INNER JOIN (Advisor INNER JOIN ResAdList ON Advisor.adID = ResAdList.adID) ON Research.resID = ResAdList.resID) INNER JOIN (Contact INNER JOIN ResCoList ON Contact.coID = ResCoList.coID) ON Research.resID = ResCoList.resID
WHERE (((Advisor.adID) Like IIf(IsNull([Forms]![ResearchManage]![selectadvisor]),'*',[Forms]![ResearchManage]![selectadvisor])) AND ((Contact.coID) Like IIf(IsNull([Forms]![ResearchManage]![selectcontact]),'*',[Forms]![ResearchManage]![selectcontact])));