Chey said:
Okay so this is my code
SELECT (SELECT Sum(Nz([Zero Enrollment,Zero Attendance], 0)) FROM [tblGrant
Completion-March] AS A WHERE Month
IN (SELECT Month FROM [tblGrant Completion-March] AS A WHERE A.Month <=
[tblGrant Completion-March].Month AND A.Month >= DateAdd('m', -5, [tblGrant
Completion-March].Month)))
AS RunReport FROM [tblGrant Completion-March];
I have just a blank form, with a command button.
The command button opens the report.
Where do I paste this code.
Under the open report code?
Also I have the checkbox in my query as true, do I need to get rid of that?
Thank you for all your help. I know I will get this.
:
Chey wrote:
I have tried somethig else maybe you could help me with.
I have a report with a sub report.
On the sub report I have a count. How do I make it to only show if the
count result is greater than or equal to 6?
This might be an easier way for me to understand. Plus I have the layout
they way I like it.
But after I get only the ones after 6, I want to be able to the diffrence
between months. Is this a okay way to approach this?
I guess if I can tackle one thing at a time, I can get this working. If
this doesn't look good then I will try the other way again.
:
Chey wrote:
SELECT Sum((SELECT Sum(Nz([Zero Enrollement, Zero Attendance], 0)) FROM
tblGrant Completion-March AS A WHERE
Month IN (SELECT Month FROM tblGrant Completion-March AS A WHERE A.Month <=
tblGrant Completion-March.Month AND A. Month >= DateAdd('m', -5, tblGrant
Completion-March. Month)))
= - 6) <> 0 AS RunReport FROM tblGrant Completion-March;
this is what I came up with. Am I right?
Now wher do I put this?
Oh one more thing Zero Enrollement, Zero Attendance is a Check box-I only
need the true boxes.
:
Chey wrote:
I have a formula question. I hope someone can help.
I have a check box.
and each month on the year for 05 and 06
if the check box is check for 6 continuous months, I need it to generate a
report.
So I guess I need to make a query with this critiera.
and example. if it is checked 5 times in a row, then not checked for the
next month, but then checked on the 7th month, it would not generate a
report. Only if it is a period of 6 months.
I hope someone can help
Thanks so much
Try this:
MyTable
ID Auto
theMonth Date/Time
CheckField Y/N
If ID is used to define the order,
SELECT Sum((SELECT Sum(Nz(A.CheckField, 0)) FROM MyTable AS A WHERE ID
IN (SELECT ID FROM MyTable AS A WHERE A.ID <= MyTable.ID AND A.ID >=
MyTable.ID - 5)) = - 6) <> 0 AS RunReport FROM MyTable;
If theMonth is used to define the order,
SELECT Sum((SELECT Sum(Nz(A.CheckField, 0)) FROM MyTable AS A WHERE
theMonth IN (SELECT theMonth FROM MyTable AS A WHERE A.theMonth <=
MyTable.theMonth AND A.theMonth >= DateAdd('m', -5, MyTable.theMonth)))
= - 6) <> 0 AS RunReport FROM MyTable;
This checks to see if the sum of the RunReport condition values for each
line of MyTable that get a six-in-a-row condition is non-zero.
James A. Fortune
(e-mail address removed)
tblGrant Completion-March also needs to be in square brackets since it
contains a space. Also, realize that the SQL I posted assumes that the
data is in a single table. E.g.,
MyTable
ID theMonth CheckField
1 1/1/05 CheckMark
2 2/1/05 CheckMark
3 3/1/05 NoCheckMark
4 4/1/05 CheckMark
5 5/1/05 CheckMark
6 6/1/05 CheckMark
7 7/1/05 NoCheckMark
8 8/1/05 NoCheckMark
9 9/1/05 NoCheckMark
10 10/1/05 NoCheckMark
11 11/1/05 NoCheckMark
12 12/1/05 NoCheckMark
13 1/1/06 NoCheckMark
Maybe I misunderstood what you meant by "each month on the year for 05
and 06." The query based on the data above will produce False. If the
third record gets checked (remember to move off the record after
checking the box) then the query will produce True.
James A. Fortune
(e-mail address removed)
You can set the .Visible property of the control to False when the value
is 6 or greater. Perhaps try the Detail_Format event of the subreport.
To get more insight into how the SQL I posted works, try examining it
like this:
SELECT (SELECT Sum(Nz(A.CheckField, 0)) FROM MyTable AS A WHERE theMonth
IN (SELECT theMonth FROM MyTable AS A WHERE A.theMonth <=
MyTable.theMonth AND A.theMonth >= DateAdd('m', -5, MyTable.theMonth)))
AS RunReport FROM MyTable;
with different combinations of checkmarks. The case where all the lines
are checked should be especially illuminating.
I don't understand what you want when you say "difference between
months." Perhaps providing an example would help.
James A. Fortune
(e-mail address removed)
The first question I have is:
Does [tblGrant Completion-March] contain all of the month values like in
the example?
Next, Is it possible for you to change the field name from Month to
theMonth like in the example without causing problems with existing
queries or reports? Month is the name of a function in Access.
Do you know how to create code for the Click event of a command button?
If you just create the code without going through Properties and the
three dots, Access may not connect the code to the button properly.
The code will look something like (air code):
Private Sub cmdRunReport_Click()
If Nz(DLookup("RunReport", "SavedQuery")) = True Then
DoCmd.OpenReport "MyReport", acViewPreview
Else
MsgBox("There are not six months in a row.")
End If
End Sub
The checkbox in the query indicates that at least one record has its
checkbox and the previous five checked. That check indicates that a -1
will be returned from the query so DLookup will return True (-1).
James A. Fortune
(e-mail address removed)