Hi Forum, access 2010.
I want to filter a report for a variable number of days and then email same.
This code is on the form command button and the operator enters W, F, M or X to declare the number of days.
This code is on the report Open event
It appears to work in that a report for either 7, 14 or 31 days is produced.
But..
Then a full report for the last 11 years is also produced.
I suspect OutputTo is running the report instead of accepting the one produced by the code earlier ??
Appreciate any advice. Bill
I want to filter a report for a variable number of days and then email same.
This code is on the form command button and the operator enters W, F, M or X to declare the number of days.
Code:
Dim Response As String
Dim ReportPeriod As String
Response = InputBox("Enter W for Week, F for Fortnight, or M for Month to select " & _
"what Repayment Report to send. Enter X to escape and not send a report", vbInformation)
If Response = "W" Then
ReportPeriod = "Week"
ElseIf Response = "F" Then
ReportPeriod = "Fortnight"
ElseIf Response = "M" Then
ReportPeriod = "Month"
ElseIf Response = "X" Then
GoTo Exit_Procedure
Else
MsgBox "You must enter either W, F, M or X. Try again."
GoTo Exit_Procedure
End If
'Produce and save report
DoCmd.OpenReport "rptRepaymentsByStatementReport", acViewNormal, , , acWindowNormal, ReportPeriod
DoCmd.OutputTo acOutputReport, "rptRepaymentsByStatementReport", acFormatPDF, "W:\Attachments\rptRepaymentsByStatementReport.pdf", 0, , , acExportQualityPrint
This code is on the report Open event
Code:
Dim strOpenArg As String
strOpenArg = Me.OpenArgs()
Select Case strOpenArg
Case "Week"
Me.Filter = "(StatementDate) Between Date()-7 And Date()"
Me.FilterOn = True
Case "Fortnight"
Me.Filter = "(tblBankStatements.StatementDate) Between Date()-14 And Date()"
Me.FilterOn = True
Case "Month"
Me.Filter = "(tblBankStatements.StatementDate) Between Date()-31 And Date()"
Me.FilterOn = True
Case Else
'No OpenArg so do nothing
End Select
It appears to work in that a report for either 7, 14 or 31 days is produced.
But..
Then a full report for the last 11 years is also produced.
I suspect OutputTo is running the report instead of accepting the one produced by the code earlier ??
Appreciate any advice. Bill