Hi All,
I have a mailing list form in my database were I need to filter organisations by 4 geographical areas. i.e. UK region, local authority, constituency and combined authority. Sometimes I will need to search for and send emails to all organisations for a certain region or local authority. The issue I am having is that not all organisations will have a combined authority so, since I have included these in the query that the form is based on, I only get records where there is a combined authority. I need to be able to identify organisations using the other criteria regardless of whether there is a combined authority or not.
I have attempted to write my own query in Access in SQL view following some advice I have found on various forums but I keep getting a syntax error and I'm not sure why. I have never written my own query in SQL view before so any help would be appreciated.
This is the query. When I save I keep getting the syntax error on join expression and it highlights the 'RegionT.Region' in the first line.
And I have included the SQL view from the original query I made using design view in case it helps.
I have a mailing list form in my database were I need to filter organisations by 4 geographical areas. i.e. UK region, local authority, constituency and combined authority. Sometimes I will need to search for and send emails to all organisations for a certain region or local authority. The issue I am having is that not all organisations will have a combined authority so, since I have included these in the query that the form is based on, I only get records where there is a combined authority. I need to be able to identify organisations using the other criteria regardless of whether there is a combined authority or not.
I have attempted to write my own query in Access in SQL view following some advice I have found on various forums but I keep getting a syntax error and I'm not sure why. I have never written my own query in SQL view before so any help would be appreciated.
This is the query. When I save I keep getting the syntax error on join expression and it highlights the 'RegionT.Region' in the first line.
Code:
SELECT OrganisationDetailsT.OrganisationName, OrganisastionDetailsT.NonMember, ContactsT.FirstName, ContactsT.LastName, ContactsT.Email, ContactsT.MainContact, RegionT.Region, LocalAuthorityT.LocalAuthority, ConstituencyT.Constituency, CombinedAuthorityT.CombinedAuthority
FROM (((((OrganisationDetailsT INNER JOIN ContactsT ON OrganisationDetailsT.ContactID = ContactsT.ContactID)
INNER JOIN OrganisationDetailsT ON RegionT.RegionID = OrganisationDetailsT.RegionID)
INNER JOIN OrganisationDetailsT ON LocalAuthorityT.LocalAuthorityID = OrganisationDetailsT.LocalAuthorityID)
INNER JOIN OrganisationDetailsT ON ConstituencyT.ConstituencyID = OrganisationDetailsT.ConstituencyID)
INNER JOIN OrganisationDetailsT ON CombinedAuthorityT.CombinedAuthorityID = OrganisationDetailsT.CombinedAuthorityID)
WHERE (RegionT.Region = [Forms]![MailingsF]![RegionSearch]
OR [Forms]![MailingsF]![RegionSearch] IS NULL)
AND (LocalAuthorityT.LocalAuthority = [Forms]![MailingsF]![LASearch]
OR [Forms]![MailingsF]![LASearch] IS NULL)
AND (ConstituencyT.Constituency = [Forms]![MailingsF]![ConstSearch]
OR [Forms]![MailingsF]![ConstSearch] IS NULL)
AND (CombinedAuthorityT.CombinedAuthority = [Forms]![MailingsF]![CombAuthSearch]
OR [Forms]![MailingsF]![CombAuthSearch] IS NULL);
And I have included the SQL view from the original query I made using design view in case it helps.
Code:
SELECT OrganisationDetailsT.OrganisationName, ContactsT.FirstName, ContactsT.LastName, ContactsT.Email, ContactsT.MainContact,
RegionT.Region, LocalAuthorityT.LocalAuthority, [FirstName] & " " & [LastName] AS Expr1, ConstituencyT.Constituency,
CombinedAuthorityT.CombinedAuthority, OrganisationDetailsT.NonMember
FROM ((ConstituencyT INNER JOIN (RegionT INNER JOIN LocalAuthorityT ON RegionT.RegionID = LocalAuthorityT.RegionID)
ON ConstituencyT.RegionID = RegionT.RegionID) INNER JOIN (OrganisationDetailsT INNER JOIN CombinedAuthorityT
ON OrganisationDetailsT.CombinedAuthorityID = CombinedAuthorityT.CombinedAuthorityID)
ON (RegionT.RegionID = OrganisationDetailsT.RegionID) AND (LocalAuthorityT.LocalAuthorityID = OrganisationDetailsT.LocalAuthorityID)
AND (ConstituencyT.ConstituencyID = OrganisationDetailsT.ConstituencyID) AND (LocalAuthorityT.CombinedAuthorityID = CombinedAuthorityT.CombinedAuthorityID)) INNER JOIN ContactsT
ON OrganisationDetailsT.OrganisationURN = ContactsT.OrganisationURN
WHERE (((ContactsT.MainContact)=True) AND ((OrganisationDetailsT.NonMember)=False)
AND ((IIf(IsNull([Forms]![MailingsF]![RegionSearch]),[Region] Like "*",[Region]=[forms]![MailingsF]![RegionSearch]))<>False)
AND ((IIf(IsNull([Forms]![MailingsF]![LASearch]),[LocalAuthority] Like "*",[LocalAuthority]=[forms]![MailingsF]![LASearch]))<>False)
AND ((IIf(IsNull([Forms]![MailingsF]![ConstSearch]),[Constituency] Like "*",[Constituency]=[forms]![MailingsF]![ConstSearch]))<>False)
AND ((IIf(IsNull([Forms]![MailingsF]![CombAuthSearch]),[CombinedAuthority] Like "*",[CombinedAuthority]=[forms]![MailingsF]![CombAuthSearch]))<>False));