At present your query uses Boolean OR operations. This will mean that any
row in the table which matches any one of the criteria will be returned, e.g.
if the user selects Facility A as Facility Name and San Francisco as Nearest
Major City then all rows where the facility is Facility A will be returned
regardless of the city in those rows along with all rows where the city is
San Francisco regardless of the facility name in those rows. Is this what
you want? If so your query as it stands should do this.
The alternative possibility would be that you want to use Boolean AND
operations, i.e. if the user selects two values in the form, Major City and
In-Field Recruiting say then only rows where those fields contain both
selected values will be returned. Its this scenario which is analogous to my
example (the fact that it used dates is immaterial, the principle is the
same). To do this you'd use Boolean ANDs and test for the parameters being
NULL in each case, which makes the controls optional, i.e. a user can
select/enter values in as few or as many controls on the form as desired.
The query would thus go like this:
SELECT Facilities.[Facility Name], Facilities.[Nearest Major US City],
Facilities.[Nearest Major City], Facilities.[In-Field Recruiting],
Facilities.[Recruiting for Off-Site Sessions],
Facilities.[In-Home/Ethnographies Recruiting], Facilities.[National
Recruiting Database]
FROM Facilities
WHERE
(Facilities.[Facility Name]=[Forms]![Facilities]![Lookup]
OR [Forms]![Facilities]![Lookup] IS NULL)
AND
(Facilities.[Nearest Major US City]=[Forms]![Lookup]![Mjr US cty]
OR [Forms]![Lookup]![Mjr US cty] IS NULL)
AND
(Facilities.[Nearest Major City]=[Forms]![Lookup]![Mjr frgn cty]
OR [Forms]![Lookup]![Mjr frgn cty] IS NULL)
AND
(Facilities.[In-Field Recruiting]=[Forms]![Lookup]![infield]
OR [Forms]![Lookup]![infield] IS NULL)
AND
(Facilities.[Recruiting for Off-Site Sessions]=[Forms]![Lookup]![offsite]
OR [Forms]![Lookup]![offsite] IS NULL)
AND
(Facilities.[In-Home/Ethnographies Recruiting]=[Forms]![Lookup]![inhome]
OR [Forms]![Lookup]![inhome] IS NULL)
AND
(Facilities.[National Recruiting Database]=[Forms]![Lookup]![nat dtb]
OR [Forms]![Lookup]![nat dtb] IS NULL);
I've split the criteria over separate lines to make it more readable; you
can do this anywhere in an SQL statement, it works just the same. Which of
these is correct in your case depends on just how you want the criteria
entered/selected in your dialogue form to be applied in the query.
Megan said:
Here is my SQL:
SELECT Facilities.[Facility Name], Facilities.[Nearest Major US City],
Facilities.[Nearest Major City], Facilities.[In-Field Recruiting],
Facilities.[Recruiting for Off-Site Sessions],
Facilities.[In-Home/Ethnographies Recruiting], Facilities.[National
Recruiting Database]
FROM Facilities
WHERE (((Facilities.[Facility Name])=[Forms]![Facilities]![Lookup])) OR
(((Facilities.[Nearest Major US City])=[Forms]![Lookup]![Mjr US cty])) OR
(((Facilities.[Nearest Major City])=[Forms]![Lookup]![Mjr frgn cty])) OR
(((Facilities.[In-Field Recruiting])=[Forms]![Lookup]![infield])) OR
(((Facilities.[Recruiting for Off-Site
Sessions])=[Forms]![Lookup]![offsite])) OR
(((Facilities.[In-Home/Ethnographies Recruiting])=[Forms]![Lookup]![inhome]))
OR (((Facilities.[National Recruiting Database])=[Forms]![Lookup]![nat dtb]));