L
LT
Hi everyone,
I was wondering if there is a way to manipulate the filter of a report
through code without opening it. I am running a bunch of reports on a per
individual basis and I need to filter by each of the individuals in a listbox
before I convert the report to PDF using Lebans awesome ReportToPDF
(http://www.lebans.com/reporttopdf.htm).
I tried opening the report, changing the filter by passing arguments through
OpenArgs, but as soon as I close it with the acSaveYes it doesn't seem to
persist the new filter.
I've included the code in case someone sees something that I am doing wrong
but if there is a way that I can modify the filter without opening the
report, that would be great (querydef?).
Thanks everyone!
LT
' FORM CODE
' Set the filter for the report
DoCmd.OpenReport "Invoice by Employee", acViewPreview, , , ,
Me.lstDistributionList.ItemData(index) & "^" & cboYear &
ConvertMonthValue(cboMonth)
' CLOSING THE REPORT SEEMS TO PREVENT IT FROM BEING PRINTED
DoCmd.Close acReport, "Invoice by Employee", acSaveYes
blRet = ConvertReportToPDF("Invoice by Employee", vbNullString, _
temporaryPdfCreationPath & "\" & sourceFile, False, False,
0, "", "", 0, 0)
' REPORT CODE
Private Sub Report_Open(Cancel As Integer)
Dim userName As String
Dim Period As String
userName = Left(OpenArgs, InStr(1, OpenArgs, "^") - 1)
Period = Right(OpenArgs, Len(OpenArgs) - InStr(1, OpenArgs, "^"))
Me.Filter = "[User Name] = '" & userName & "' AND " & _
"[Period] = '" & Period & "'"
End Sub
I was wondering if there is a way to manipulate the filter of a report
through code without opening it. I am running a bunch of reports on a per
individual basis and I need to filter by each of the individuals in a listbox
before I convert the report to PDF using Lebans awesome ReportToPDF
(http://www.lebans.com/reporttopdf.htm).
I tried opening the report, changing the filter by passing arguments through
OpenArgs, but as soon as I close it with the acSaveYes it doesn't seem to
persist the new filter.
I've included the code in case someone sees something that I am doing wrong
but if there is a way that I can modify the filter without opening the
report, that would be great (querydef?).
Thanks everyone!
LT
' FORM CODE
' Set the filter for the report
DoCmd.OpenReport "Invoice by Employee", acViewPreview, , , ,
Me.lstDistributionList.ItemData(index) & "^" & cboYear &
ConvertMonthValue(cboMonth)
' CLOSING THE REPORT SEEMS TO PREVENT IT FROM BEING PRINTED
DoCmd.Close acReport, "Invoice by Employee", acSaveYes
blRet = ConvertReportToPDF("Invoice by Employee", vbNullString, _
temporaryPdfCreationPath & "\" & sourceFile, False, False,
0, "", "", 0, 0)
' REPORT CODE
Private Sub Report_Open(Cancel As Integer)
Dim userName As String
Dim Period As String
userName = Left(OpenArgs, InStr(1, OpenArgs, "^") - 1)
Period = Right(OpenArgs, Len(OpenArgs) - InStr(1, OpenArgs, "^"))
Me.Filter = "[User Name] = '" & userName & "' AND " & _
"[Period] = '" & Period & "'"
End Sub