ReportToPDF with DataRange

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
 
A

Albert D. Kallal

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.
 
J

John B

Albert,
may I say/write Thank You very much for your precious explanations and
suggestion that help me really a lot.

Regards
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top