ReportToPDF with Filter

B

Bill

I’m a newbe to access and trying to learn as I develop. I’ve learned a
little but I’m stumped! I’ve downloaded Steven Leban’s ReportToPDF and need
to “filter†it to the current report. So to me it makes sense to first print
the current report:

Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ReportID] = """ & Me.[ReportID] & """"
DoCmd.OpenReport "IR_Report", acViewPreview, , strWhere
End If

Then call the ReportToPDF function:

Dim blRet As Boolean
' Call our convert function
' Please note the last param signals whether to perform
' font embedding or not. I have turned font embedding ON for this example.
blRet = ConvertReportToPDF(Me.[IR_Report], vbNullString, _
Me.[IR_Report].Value & ".pdf", False, True, 150, "", "", 0, 0, 0)
' To modify the above call to force the File Save Dialog to select the name
and path
' for the saved PDF file simply change the ShowSaveFileDialog param to TRUE.

End Sub

But I get the error of “Microsoft Office Access can’t find the field ‘|’
referred to in your expression.

Where is this coming from?? I’m sooo lost!!!

Thanks for the help

Bill



stLinkCriteria = "[Some Field]=" & "'" & msomevalue & "'"
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
DoCmd.Minimize
Call convertreporttopdf(stDocName, ,
strPDFOutputFilePathAndName & ".pdf", False, False)
DoCmd.Close acReport, stDocName
 
B

Bill

Ok. So I got it to work, but I'd like to automate it a little more. The way
I'm doing it is printing a record (to view) then calling the ReportToPDF on
the report open command. Then we need to click another button to generate the
PDF.

Anyway to skip this step? Thx
 
A

Albert D. Kallal

just go:

code here to open your report with filter....

strReportName = "name of your report"
strPDFName = "full path name + name of pdf"
DoCmd.OpenReport strReportName, acViewPreview, , strWhere
Reports(strReportName).Visible = False

Call ConvertReportToPDF(strReportName, , strDocName, False, False)

DoCmd.Close acReport, strReportName


that is it, so I count about 2 extra lines of code to add after you open the
report.....

note in the above you don't want to forget to close the report.....
 
B

Bill

Ok I got it to work!!! THANK YOU! I had to hard code some things in. Here's
what I did:

Private Sub Print_Rpt_Click()
' ok lets start the record to print
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ReportID] = """ & Me.[ReportID] & """"
DoCmd.OpenReport "IR_Report", acViewPreview, , strWhere
End If

' ok now lets try to export it to a PDF hopefully using the IR number in
the filename

strReportName = "IR_Report"
strPDFName = "C:\Sec_Reports\new.pdf"
DoCmd.OpenReport strReportName, acViewPreview, , strWhere
Reports(strReportName).Visible = False

Call ConvertReportToPDF("IR_Report", , _
"C:\Sec_Reports\" & Me.ReportID & ".pdf", False, False)

DoCmd.Close acReport, strReportName

End Sub
 

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