Hi,
In a database am building, I want to run a query with the criteria dependant on which field the user populates in a form.
The form has a number of fields that the user can select from including our reference number, the client's reference number and the site address.
I would like the user to be able to select the site address using a wildcard so that they can enter a part of the address such as "This Street" instead of "45 This Street" and the user be presented with all of the records matching "This Street".
I tried using the criteria:
Which works perfectly as long as this field is populated. If this field is not populated, entering details in any other field bring up every record in the database.
After some searching, I believe that I need to use an IIF function to resolve this however I cannot get this to work. The code I have played around with so far is:
If it is of any help, the full sql of my query is:
Can you please show me where I am going wrong.
Thanks
In a database am building, I want to run a query with the criteria dependant on which field the user populates in a form.
The form has a number of fields that the user can select from including our reference number, the client's reference number and the site address.
I would like the user to be able to select the site address using a wildcard so that they can enter a part of the address such as "This Street" instead of "45 This Street" and the user be presented with all of the records matching "This Street".
I tried using the criteria:
Code:
Like "*" & [Forms]![SearchJobs]![SearchAddressLine1] & "*"
After some searching, I believe that I need to use an IIF function to resolve this however I cannot get this to work. The code I have played around with so far is:
Code:
IIf(IsNull([Forms]![SearchJobs]![SearchAddressLine1]),Null,[Forms]![SearchJobs]![SearchAddressLine1] & "*")
Code:
SELECT Jobs.JobsSalesEnquiryRecordNumber, Jobs.JobsJobStatus, Jobs.JobsEnquiryDate, Jobs.JobsTakenBy, ClientDetails.ClientDetailsURN, ClientDetails.ClientDetailsName, ClientDetails.ClientDetailsAddressLine1, ClientDetails.ClientDetailsAddressLine2, ClientDetails.ClientDetailsAddressLine3, ClientDetails.ClientClientPostCode, Jobs.JobsClientJobNumber, Jobs.JobsAlternativeClientJobNumber, Jobs.JobsClientContact, ClientDetails.ClientDetailsTelephone, SiteDetails.SiteDetailsContactName, SiteDetails.SiteDetailsContactTelephone, SiteDetails.SiteDetailsURN, SiteDetails.SiteDetailsAddressLine1, SiteDetails.SiteDetailsAddressLine2, SiteDetails.SiteDetailsAddressLine3, SiteDetails.SiteDetailsPostCode1, SiteDetails.SiteDetailsPostCode2, AgentDetails.AgentDetailsName, AgentDetails.AgentDetailsAddressLine1, AgentDetails.AgentDetailsAddressLine2, AgentDetails.AgentDetailsAddressLine3, AgentDetails.AgentDetailsPostCode, AgentDetails.AgentDetailsTelephone, Jobs.JobsWorkRequired, Jobs.JobsQuoteDueBy, Jobs.JobsQuotesURN, Jobs.JobsQuotesStarted, Jobs.JobsQuoteCompletedBy, Jobs.JobsQuoteSentDate, Jobs.JobsQuoteSentBy, Jobs.JobsQuoteSentTo, Jobs.JobsKillQuote, Jobs.JobSubcontractorURN, SubContractorDetails.SubContractorDetailsName, Jobs.JobsSubcontractorAllocationDate, SubContractorDetails.SubContractorDetailsEmail, Jobs.JobsOperativeURN, OperativesDetails.OperativesDetailsFirstName, OperativesDetails.OperativesDetailsSecondName, Jobs.JobsOperativeAllocationDate, OperativesDetails.OperativesDetailsEmail, Jobs.JobsLive, Jobs.JobDueBy, Jobs.JobsPlannedDate, Jobs.JobsPropertyAssessmentURN, Jobs.JobsPropertyAssessmentCompleted, Jobs.JobsCompletionDate, Jobs.JobsJobCompleted, Jobs.JobsPicturesSent, Jobs.JobsPicturesSentBy, Jobs.JobsPicturesSentDate, Jobs.JobsPicturesSentTo, Jobs.JobsCompletionPicturesSent, Jobs.JobsCompletionPicturesSentBy, Jobs.JobsCompletionPicturesSentTo, Jobs.JobsCompletionPicturesSentDate, Jobs.JobsInvoiceDate, Jobs.JobsInvoiced, Jobs.JobsJobNote1, Jobs.JobsJobNoteDate1, Jobs.JobsJobNote2, Jobs.JobsJobNoteDate2, Jobs.JobsJobNote3, Jobs.JobsJobNoteDate3, Jobs.JobsJobNote4, Jobs.JobsJobNoteDate4, Jobs.JobsJobNote5, Jobs.JobsJobNoteDate5, Jobs.JobsJobNote6, Jobs.JobsJobNoteDate6, Jobs.JobsJobNote7, Jobs.JobsJobNoteDate7, Jobs.JobsJobNote8, Jobs.JobsJobNoteDate8, Jobs.JobsJobNote9, Jobs.JobsJobNoteDate9, Jobs.JobsJobNote10, Jobs.JobsJobNoteDate10, Jobs.JobsPropertyAssessmentSentTo, Jobs.JobsPropertyAssessmentSentDate, Jobs.JobsQuoteCompleted, Jobs.JobsRecall
FROM OperativesDetails RIGHT JOIN (SubContractorDetails RIGHT JOIN (AgentDetails RIGHT JOIN (SiteDetails RIGHT JOIN (ClientDetails INNER JOIN Jobs ON ClientDetails.ClientDetailsURN = Jobs.JobsClientURN) ON SiteDetails.SiteDetailsURN = Jobs.JobsSiteURN) ON AgentDetails.AgentDetailsURN = Jobs.JobsAgentURN) ON SubContractorDetails.SubContractorDetailsURN = Jobs.JobSubcontractorURN) ON OperativesDetails.OperativesDetailsURN = Jobs.JobsOperativeURN
WHERE (((Jobs.JobsSalesEnquiryRecordNumber)=[Forms]![SearchJobs]![SearchAdvancedReferenceNumber])) OR (((SiteDetails.SiteDetailsAddressLine1)=IIf(IsNull([Forms]![SearchJobs]![SearchAddressLine1]),Null,[Forms]![SearchJobs]![SearchAddressLine1] & "*"))) OR (((ClientDetails.ClientDetailsURN)=[Forms]![SearchJobs]![SearchClientCombo]) AND ((Jobs.JobsClientJobNumber)=[Forms]![SearchJobs]![SearchClientReferenceNumber])) OR (((SiteDetails.SiteDetailsPostCode1)=[Forms]![SearchJobs]![SearchPostCode1]) AND ((SiteDetails.SiteDetailsPostCode2)=[Forms]![SearchJobs]![SearchPostCode2])) OR (((ClientDetails.ClientDetailsURN)=[Forms]![SearchJobs]![SearchClientCombo]) AND ((Jobs.JobsAlternativeClientJobNumber)=[Forms]![SearchJobs]![SearchClientReferenceNumber])) OR (((SiteDetails.SiteDetailsURN)=[Forms]![SearchJobs]![Combo38]))
ORDER BY Jobs.JobsSalesEnquiryRecordNumber DESC;
Thanks