dad wrote:
I am building a database to track the maintenance records on a fleet
of cars. I need to run a report on that will display data based on
whether a box is checked or not (i.e. all cars that have the oil
change box checked, or a report that shows all cars and lists all the
boxes that each have checked (for a list of maintennace due). Anyone
out there have any advice? Any would be appreciated. Thanks in
advance!
When you open a report you can tell the report what you want to filter.
DoCmd.OpenRepor t "ReportName ", , , "WhereClauseFil ter"
In your case, most likely you call the report from a form. Let's call
the form RptFilter. Here you could present what you want to filter
Using your above example, you could have 2 lines; description & 2
checkboxes.
FilterField Filter? Yes/No?
Oil Change OCF Val1
Maint Due MDF Val2
The filter names are OCF/MDF as checkboxes. Val is a checkbox. Now if
you have a command button to print the report, first create a filter,
then call report
Dim strFilter As String
If Me.OCF Then strFilter = "OilChange = " & Me.Val1 & " And "
If Me.MDF Then strFilter = strFilter & _
"Maint Due = " & Me.Val2 & " And "
'remove And
If strFilter > "" Then strFilter = Left(strFilter, Len(strFilter)-5)
DoCmd.OpenRepor t "ReportName ", , , strFilter
This will open the report and filter as necessary.
I wouldn't bother filtering the report's recordsource SQL, do it from
the Where clause filter. This way you remain flexible.
I sometimes create a field to store a description of the filter.
Dim str As String
If Me.OCF Then str = "OilChange " & IIF(Me.Val1,"Y" ,"N") & space(4)
If Me.MDF Then str = str & ""Maint Due " & IIF(Me.Val1,"Y" ,"N")
Me.FilterStr = str
Now when I call the report, in the report header I have a field to
present the filter string. Let's say the form name is Rpt. The control
source of the text box to present the filter would be
="Filtered As " & Forms!Rpt!Filte rStr
That way the user knows, if he looks at the report later, what the
report was filtered on.