Can an option group be Null? By the way, there are three more fields, two of
them Date fields which can be Null, a single Date, or a range of Dates. I've
decided on a brute force approach.
I am going into the SQL statement and changing the Where clause in the
Select statement. When the user clicks OK on the Criteria form, the _Click()
event analyzes the user's responses and constructs a Where clause within the
Select statement. In the Report_Open() method, I assign the new Select
statement to the RecordSource property of the Report.
So instead of being based on a predefined query with flexible criteria, as
was my original intent, I am basing the Report on my constructed Select
statement which has hardcoded criteria based on the current set of user
responses.
Within the Where clause I have four subclauses based on the user's response
to each of the four criteria fields. I construct each subclause separately
and then chain them together, e.g.,
strAssignedToClause = " AND ((DataLog.AssignedTo)='Smith, John'"
strDateBegunClause = " AND ((DataLog.DateBegun)=#" & Me.DateBegun & "#)
And of course a subclause might also be "", which occurs when the user
leaves a criteria field blank.
When I have all my subclauses constructed, I '&' them together to form the
Where clause inside my Select statement. It's still under test, but so far
appears to work.
Thank you for your efforts on my behalf, John.
John W. Vinson said:
I actually have four possible criteria for the AssignedTo field on my
Criteria form which is set up as an option group. If AssignedTo is:
Null, I want all records including those with null values;
Name, I want all records with that name in AssignedTo field;
No Assignments, All records with Null value in AssignedTo field;
All Assignments, All records with non-null values in AssignedTo field.
I had been thinking in terms of deciphering which of the four criteria I
want from the criteria form, then writing a value or string into the query
(from within an IIF in the query) to retrieve the associated records. I'm
beginning to realize that may not be the correct strategy. Or is it? I'm
stumped.
It's probably not the best design but it can be made to work.
Let's assume that the option group has three controls, with 1 being Name,
2 No
Assignments, and 3 All Assignments, and that it can be left null (it
should
probably be an unbound control).
Try a criterion of
WHERE
([Forms]![Criteria]![AssignedTo] IS NULL)
OR
([Forms]![Criteria]![AssignedTo] = 1
AND [Namefield] = [Forms]![Criteria]![txtName])
OR
([Forms]![Criteria]![AssignedTo] = 2
AND [Namefield] IS NULL)
OR
([Forms]![Criteria]![AssignedTo] = 3
AND [Namefield] IS NOT NULL)
John W. Vinson [MVP]