ReportToPDF with DataRange

  • Thread starter Thread starter John B
  • Start date Start date
J

John B

Hi,
I am trying to adapt the Mr Lebans routine to export to Pdf and I would like
to print the report based on the data range.
Without the data range is OK, but I don't know where to pass "DataRange"
criteria in the function blRet.

Any suggestions is really appreciate.
Thanks and Regards
John

Private Sub cmdReportToPDF_Click()
Dim blRet As Boolean
Dim stDocName As String

stDocName = "rptOrder"
'Dim DataRange As String
DataRange = "[DateOrder] between #" & [Forms]![frmReport]![txtdatefrom] "#
and #" & [Forms]![frmReport]![txtDateTo] & "#"

blRet = ConvertReportToPDF(stDocName, vbNullString, stDocName & ".pdf",
False, True, 0, "", "", 0, 0)
End Sub
 
In a nutshell, you simply open the report first, and then when you call the
report to pdf, it will use the currently **opened** report.
stDocName = "rptOrder"
'Dim DataRange As String
DataRange = "[DateOrder] between #" & [Forms]![frmReport]![txtdatefrom] "#
and #" & [Forms]![frmReport]![txtDateTo] & "#"

docmd.OpenReport strdocName,acViewPreview,,dataRange

blRet = ConvertReportToPDF(stDocName, vbNullString, stDocName & ".pdf",
False, True, 0, "", "", 0, 0)

DoCmd.Close acReport, strReportName <-- don't forget to close report

I'm not 100% sure, but if you don't want the report slashing on the screen I
think on the next line right after the open report you can go:

Reports(strDocName).visible = false

anyway, don't forget to close the report.

The above approach simply means that if you open the report already, the
convert to pdf will respect the report that is already open, and use its
currently engaged filter or "where" clause that is restricting the records
in the report.
 
Albert,
may I say/write Thank You very much for your precious explanations and
suggestion that help me really a lot.

Regards
John
 
Back
Top