Tom,
I believe there is a logic problem in the criteria. John has already pointed
out the "Form" instead of "Forms" problem.
The logic problem I believe is here.
((ScheduledRuns.Sunday)=[Form]![ScheduledRuns]![Sunday])) OR
(((ScheduledRuns.Monday)=[Form]![ScheduledRuns]![Monday])) OR
(((ScheduledRuns.Tuesday)=[Form]![ScheduledRuns]![Tuesday])) OR
(((ScheduledRuns.Wednesday)=[Form]![ScheduledRuns]![Wednesday])) OR
(((ScheduledRuns.Thursday)=[Form]![ScheduledRuns]![Thursday])) OR
(((ScheduledRuns.Friday)=[Form]![ScheduledRuns]![Friday])) OR
(((ScheduledRuns.Saturday)=[Form]![ScheduledRuns]![Saturday]));
If ScheduledRuns.Sunday is False and the checkbox is False, then that record
will be returned. If I'm understanding correctly, you only want the record
returned if the checkbox is checked (True). Using a Triple State checkbox
and having them Null for not selected, as your previous code set them, may
help because the record in the table is probably True or False, so Null
won't match. However, what might be easier is creating the SQL in the code.
Check each checkbox and only include lines for the checkboxes that are True.
You would then assign the SQL you build to the SQL property of the query.
This will change the query. Once you've done that, open the report and it
will use the new SQL in the query.
Example:
Dim intTrueCount As Integer
strSQL = "SELECT ScheduledRuns.PtLastName, ScheduledRuns.StartDate, " & _
"ScheduledRuns.EndDate, ScheduledRuns.ApptTime, ScheduledRuns.ScheduledTime,
" & _
"ScheduledRuns.TrFacility, ScheduledRuns.RecFacility, ScheduledRuns.Sunday,
" & _
"ScheduledRuns.Monday, ScheduledRuns.Tuesday, ScheduledRuns.Wednesday, " & _
"ScheduledRuns.Thursday, ScheduledRuns.Friday, ScheduledRuns.Saturday " & _
"FROM ScheduledRuns " & _
"WHERE (((ScheduledRuns.StartDate) Between IIf(Date()<[EndDate],Date()) And
" & _
"[StartDate]) AND ((ScheduledRuns.EndDate) Between " & _
"IIf(Date()>[StartDate],Date()) And [EndDate]) AND "
If Me.chkSunday = True Then
strSQL = strSQL & "ScheduledRuns.Sunday = True And "
intTrueCount = intTrueCount + 1
End If
If Me.chkMonday = True Then
strSQL = strSQL & "ScheduledRuns.Monday= True And "
intTrueCount = intTrueCount + 1
End If
If Me.chkTuesday = True Then
strSQL = strSQL & "ScheduledRuns.Tuesday= True And "
intTrueCount = intTrueCount + 1
End If
If Me.chkWednesday = True Then
strSQL = strSQL & "ScheduledRuns.Wednesday= True And "
intTrueCount = intTrueCount + 1
End If
If Me.chkThursday = True Then
strSQL = strSQL & "ScheduledRuns.Thursday= True And "
intTrueCount = intTrueCount + 1
End If
If Me.chkFriday = True Then
strSQL = strSQL & "ScheduledRuns.Friday= True And "
intTrueCount = intTrueCount + 1
End If
If Me.chkSaturday = True Then
strSQL = strSQL & "ScheduledRuns.Saturday= True And "
intTrueCount = intTrueCount + 1
End If
If intTrueCount = 0 Then
Msgbox "No Selections Made"
Exit Sub
End If
'Remove the trailing "AND "
strSQL = Left(strSQL, Len(strSQL) - 4) & ";"
CurrentDb.Queydefs("NameOfQuery").SQL = strSQL
DoCmd.OpenReport "ScheduledRunsTodayList", acPreview
Of course, adjust all names to the correct names for your fields and form
controls. You won't need to refer to the form in the SQL (query) because you
will be providing the desired value (True) directly. This is possible since
you are dynamically rewriting the query as needed. The only days of the week
that will be included in the query are those that are checked.
--
Wayne Morgan
MS Access MVP
Tom said:
I found the first problem, checkbox control name, but have not fixed it
yet.
Name of Form: ScheduledRuns
Name of each checkbox control:
Sun
Mon
Tue
Wed
Thu
Fri
Sat
SQL Statement:
SELECT ScheduledRuns.PtLastName, ScheduledRuns.StartDate,
ScheduledRuns.EndDate, ScheduledRuns.ApptTime,
ScheduledRuns.ScheduledTime,
ScheduledRuns.TrFacility, ScheduledRuns.RecFacility, ScheduledRuns.Sunday,
ScheduledRuns.Monday, ScheduledRuns.Tuesday, ScheduledRuns.Wednesday,
ScheduledRuns.Thursday, ScheduledRuns.Friday, ScheduledRuns.Saturday
FROM ScheduledRuns
WHERE (((ScheduledRuns.StartDate) Between IIf(Date()<[EndDate],Date()) And
[StartDate]) AND ((ScheduledRuns.EndDate) Between
IIf(Date()>[StartDate],Date()) And [EndDate]) AND
((ScheduledRuns.Sunday)=[Form]![ScheduledRuns]![Sunday])) OR
(((ScheduledRuns.Monday)=[Form]![ScheduledRuns]![Monday])) OR
(((ScheduledRuns.Tuesday)=[Form]![ScheduledRuns]![Tuesday])) OR
(((ScheduledRuns.Wednesday)=[Form]![ScheduledRuns]![Wednesday])) OR
(((ScheduledRuns.Thursday)=[Form]![ScheduledRuns]![Thursday])) OR
(((ScheduledRuns.Friday)=[Form]![ScheduledRuns]![Friday])) OR
(((ScheduledRuns.Saturday)=[Form]![ScheduledRuns]![Saturday]));
I appologize for not informing you of the other part of the query. This
limits the
reports to dates between the "StartDate" and "EndDate" but >= today.
That part needs to be there and it is working fine.
Tom
tina said:
ok, first let's fix your code. it opens the report twice. take out one of
the two DoCmd.OpenReport lines. if you want to *see* the report rather
than
immediately print it, take out the second line.
next, sounds like your form references are incorrect, because you should
not
be getting any message boxes at all when you click the command button.
please tell us the name of your form - the name that shows on the list of
forms on the Form "tab" in the database window. and tell us the name of
each
checkbox control on the form - in form design, click on a checkbox
control
and, in the Properties box, click on the Other tab, and look at the Name
property.
next, open your query in design view. on the menu bar, click View | SQL
View. higlight the *whole* SQL statement from beginning to end, copy it,
and
paste it into your post so we can look at it.
hth