I have a form that has 6 fields (job, lsd, sec, twp, rge ,mer)
the form gives data to a query.
a record is made up of the 6 fields above, some are null and some have data (numbers)
I want the query to constrain only by the fields that are filled in
i.e. if the user only types in a value for sec(5) and a value for twp(27) the query should return all records that have a value of 5 for sec and 27 for twp.
My current sql (below) will only constrain the records if you have more than one field with data, otherwise it return all records. If you have more than one field with data it will constrain by one less field.
i.e. if you have a value for lsd, sec- it will only constrain by the value for lsd
if you have value for lsd, sec, twp- it will only constrain by lsd,sec,
sql-
SELECT [located in].Job, [located in].Lsd, [located in].Section, [located in].Township, [located in].Range, [located in].Meridian, Job.well
FROM Job LEFT JOIN [located in] ON Job.job = [located in].Job
WHERE (((IIf(IsNull([forms].[SEARCH]![JOB]),IsNull([forms].[SEARCH]![JOB]),[located in].[JOB]=[forms].[SEARCH]![JOB]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![LSD]),IsNull([forms].[SEARCH]![LSD]),[located in].[LSD]=[forms].[SEARCH]![LSD]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![SECTION]),IsNull([forms].[SEARCH]![SECTION]),[located in].[SECTION]=[forms].[SEARCH]![SECTION]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![TOWNSHIP]),IsNull([forms].[SEARCH]![TOWNSHIP]),[located in].[TOWNSHIP]=[forms].[SEARCH]![TOWNSHIP]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![RANGE]),IsNull([forms].[SEARCH]![RANGE]),[located in].[RANGE]=[forms].[SEARCH]![RANGE]))<>False) AND ((IIf(IsNull([forms].[SEARCH]![MERIDIAN]),IsNull([forms].[SEARCH]![MERIDIAN]),[located in].[MERIDIAN]=[forms].[SEARCH]![MERIDIAN]))<>False));
what am I doing wrong??
the form gives data to a query.
a record is made up of the 6 fields above, some are null and some have data (numbers)
I want the query to constrain only by the fields that are filled in
i.e. if the user only types in a value for sec(5) and a value for twp(27) the query should return all records that have a value of 5 for sec and 27 for twp.
My current sql (below) will only constrain the records if you have more than one field with data, otherwise it return all records. If you have more than one field with data it will constrain by one less field.
i.e. if you have a value for lsd, sec- it will only constrain by the value for lsd
if you have value for lsd, sec, twp- it will only constrain by lsd,sec,
sql-
SELECT [located in].Job, [located in].Lsd, [located in].Section, [located in].Township, [located in].Range, [located in].Meridian, Job.well
FROM Job LEFT JOIN [located in] ON Job.job = [located in].Job
WHERE (((IIf(IsNull([forms].[SEARCH]![JOB]),IsNull([forms].[SEARCH]![JOB]),[located in].[JOB]=[forms].[SEARCH]![JOB]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![LSD]),IsNull([forms].[SEARCH]![LSD]),[located in].[LSD]=[forms].[SEARCH]![LSD]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![SECTION]),IsNull([forms].[SEARCH]![SECTION]),[located in].[SECTION]=[forms].[SEARCH]![SECTION]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![TOWNSHIP]),IsNull([forms].[SEARCH]![TOWNSHIP]),[located in].[TOWNSHIP]=[forms].[SEARCH]![TOWNSHIP]))<>False)
AND ((IIf(IsNull([forms].[SEARCH]![RANGE]),IsNull([forms].[SEARCH]![RANGE]),[located in].[RANGE]=[forms].[SEARCH]![RANGE]))<>False) AND ((IIf(IsNull([forms].[SEARCH]![MERIDIAN]),IsNull([forms].[SEARCH]![MERIDIAN]),[located in].[MERIDIAN]=[forms].[SEARCH]![MERIDIAN]))<>False));
what am I doing wrong??