2

I'm looking to split a multi-page access report up into individual pdf files based on a Customer ID and then saving those pdf files based on the Customer Name (or ID).

I've looked into 'printing'/'converting' the report into one massive pdf file and splitting it there, but some customer invoices span two+ pages, therefore splitting that one pdf file page-by-page doesn't work.

Any help would be greatly appreciated; if anyone needs more clarification on anything, don't hesitate to let me know.

0

2 Answers 2

4

This can be easy with Access 2007 (see note below) or later.

Open your report using the WhereCondition parameter to limit the record source to a specific customer.

DoCmd.OpenReport "rptFoo", acViewPreview, , "Customer_ID = 1"

Then use OutputTo to save it as PDF with a file name you supply.

DoCmd.OutputTo acOutputReport, "", acFormatPDF, "Spacely_Sprockets.pdf"

Close the report afterward.

DoCmd.Close acReport, "rptFoo"

You could create a procedure which opens a recordset for Customer_ID and Customer_Name data, then use those 3 commands with values from each row.

If your Access version is older than 2007, you'll have to tell us about the method you're using to create PDF files.

Note: For Access 2007, Office Service Pack 2 provides Built-in Save As PDF/XPS support.

2

PDF printing is available with MS Access 2010, for 2007, you can install an add-on from Microsoft : Print, share, and protect files in the PDF and XPS file formats

For versions prior to 2007, you can use :

  • Stephen LeBan's ReportToPDF consists of just two DLLs but only works with MS Access

  • CutePDF is free and easy to use.

  • PDFCreator is also free and can be fully automated with VBA (though I have not used it lately, I believe this feature is still available)

  • Any number of paid-for PDF creators.

The WHERE argument for OpenReport has been available since the 2003 version (also OpenReport 2010)

To print a report for all customers for version 2003, 2007 and 2010, you can loop through the relevant file and

Dim rs AS DAO.Recordset
Set rs = CurrentDB.OpenRecordset("SELECT DISTINCT CustimerID FROM Invoices")

   Do While Not rs.EOF
      ''expression.OpenReport(ReportName, View, FilterName, 
      ''      WhereCondition, WindowMode) -- 2010 has OpenArgs

      DoCmd.OpenReport "Invoices",<..>,,"CustomerID=" & rs!CustomerID
      ''OutputTo or other relevant code

      rs.MoveNext
   Loop

Getting a PDF then depends on your version and the tools you have installed. If you are using PDFCreator or CutePDF, for example, you can use acViewNormal for the view. PDFCreator set up will allow you to assign a file name in advance, for CutePDF, you will have to fill in a file name. For Access 2007 and 2010, you can use OutputTo, as has already been mentioned, so acViewPreview is best.

To email a report for 2007 and 2010, you can use SendObject. For earlier versions, you will need quite a bit more code. The easiest option is probably to automate Outlook.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.