Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
865 views
in Technique[技术] by (71.8m points)

vba - Splitting a Multi-Page MS Access report into individual pdf files based on a Customer ID?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...