I have a report based on a query that the user filters by year by selecting an Option button on a form. I would like the report header to be specific to the year selected by the user. I've currently got an unbound text box that formats the Report Header - (if [DateRequested] Between #1/1/2009# And #12/31/2009# then "2009 Budget Report". This is working fine when the user selects and individual year, but there is also an option button that allows the user to select All years. Below is the code that filters and displays the report - would there be a way to add code here to define the report header as well?
Private Sub cmdBudget_Click()
Dim strFilter1 As String
Dim strDocName As String
Dim rpt As Report
Dim strAddCriteria As String
'Determine which year
Select Case BudgetYear
Case 1 '2009
strFilter1 = "DateRequested Between #01/01/2009# And #12/31/2009#"
Case 2 '2010
strFilter1 = "DateRequested Between #01/01/2010# And #12/31/2010#"
Case 3 '2011
strFilter1 = "DateRequested Between #01/01/2011# And #12/31/2011#"
Case 4 '2012
strFilter1 = "DateRequested Between #01/01/2012# And #12/31/2012#"
Case 5 'All years
strFilter1 = Me.FilterOn = False
End Select
'compile filter criteria
strAddCriteria = "(" & strFilter1 & ")"
'open report in design view, set the sort order, close design view, then open a preview
strDocName = "rptBudgetRecapOverall"
DoCmd.OpenReport strDocName, acViewDesign
Set rpt = Reports(strDocName)
rpt.OrderByOn = True
rpt.OrderBy = "DonationType"
DoCmd.Close acReport, strDocName, acSaveYes
DoCmd.OpenReport strDocName, acViewPreview, , strAddCriteria
DoCmd.Close acForm, "frmReportSelectionTabs"
End Sub
Thank you in advance.
Private Sub cmdBudget_Click()
Dim strFilter1 As String
Dim strDocName As String
Dim rpt As Report
Dim strAddCriteria As String
'Determine which year
Select Case BudgetYear
Case 1 '2009
strFilter1 = "DateRequested Between #01/01/2009# And #12/31/2009#"
Case 2 '2010
strFilter1 = "DateRequested Between #01/01/2010# And #12/31/2010#"
Case 3 '2011
strFilter1 = "DateRequested Between #01/01/2011# And #12/31/2011#"
Case 4 '2012
strFilter1 = "DateRequested Between #01/01/2012# And #12/31/2012#"
Case 5 'All years
strFilter1 = Me.FilterOn = False
End Select
'compile filter criteria
strAddCriteria = "(" & strFilter1 & ")"
'open report in design view, set the sort order, close design view, then open a preview
strDocName = "rptBudgetRecapOverall"
DoCmd.OpenReport strDocName, acViewDesign
Set rpt = Reports(strDocName)
rpt.OrderByOn = True
rpt.OrderBy = "DonationType"
DoCmd.Close acReport, strDocName, acSaveYes
DoCmd.OpenReport strDocName, acViewPreview, , strAddCriteria
DoCmd.Close acForm, "frmReportSelectionTabs"
End Sub
Thank you in advance.