Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do we send a report to PDF with a "Where" clause or Add Where Clause to "OutputTo 1

Status
Not open for further replies.

ICCIIT

Technical User
Jul 21, 2003
62
GB

Access 2010

As part of a Loop procedure I have a OpenReport command that has a "Where" statement included so that it outputs each Looped instance to our printer as below:-

DoCmd.OpenReport "rptrenewalinvite", , , "tblPolicy.LpPolID='" & PolicyID & "'"

We are now wanting to create PDF files as part of the loop rather than output to printer but this does not seem to be an option with the "OpenReport" command and it seems I need the "OutPutTo" command:-

DoCmd.OutputTo acOutputReport, "rptrenewalinvite", acFormatPDF, Path & ReportName & ".pdf"

The problem is, we cannot add the "Where" clause to the OutPutTo command!

Any ideas how we can achieve this??

Thanks - in hope!
 
Assuming ReportName is being updated in the loop, simply change

Code:
[blue]DoCmd.OpenReport "rptrenewalinvite", , , "tblPolicy.LpPolID='" & PolicyID & "'"[/blue]

to

Code:
[blue]DoCmd.OpenReport "rptrenewalinvite", acViewReport, , "tblPolicy.LpPolID='" & PolicyID & "'" 
DoCmd.OutputTo acOutputReport, "rptrenewalinvite", acFormatPDF, Path & ReportName & ".pdf"[/blue]

That should do the trick

You'll probably want to add the following after the loop completes:

Code:
[blue]DoCmd.Close acReport, "rptrenewalinvite"[/blue]
 
Thanks Strongm

After I posted I did find the same solution elsewhere and it works well but annoyed me when each loop previewed the document! so within the report I have added a docmnd.Minimize within the On Open event which did the trick!

Its not the most elegant solution but it works, I am little surprised that MS have not included a pdf Option within the OpenReport cmd or added a "Where" option to the OutputTo but there we go we can't have everything we want I suppose.

Thanks again
 
>docmnd.Minimize

Just surround the loop with

Application.Echo False
... loop stuff
Application.Echo True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top