Generating Multi-Page reports via Visual Basic.

B

Bailey

Currently I have a basic Report that runs from a query. Statements are
created for employees in a single multi-page report. I need to run something
similar, using the same query, except that for each record we need to create
a separate report file. Each report file needs to be saved as PDF format
with the file name dynamically generated by a combination of db data
(Employee ID), and date. I need to have Access automatically choose the file
name based on the field labeled “Employee IDâ€. The entire process needs to
be automated, started only with the click of a form button on a switchboard.
I have a third party application installed that allows me to print documents
directly to a PDF file. Here is the code that I've come up with so far. Right
now it just prints the entire report and I'm not sure what the problem is.

Sub subExportMultiReport()

Dim strSQL As String

Dim strReport As String

Dim strFileName As String

Dim rpt As Report

Dim rs As Recordset

Dim intI As Integer

strReport = "channel statements"

strSQL = "Select [Employee ID] From channel"

Set rs = CurrentDb.OpenRecordset(strSQL)

rs.MoveFirst

i = 0

Do Until rs.EOF

DoCmd.OpenReport "Channel Statements", acViewNormal, "Employee ID",
, acHidden

Set rpt = Application.Reports(strReport)

rpt.FilterOn = False

rpt.Filter = "Employee ID"

rpt.FilterOn = True

DoCmd.Close acReport, "Channel Statments", acSaveYes

strFileName = ("C:\Documents and Settings\baidu01\Desktop\test\") &
"rs![Employee ID]" & ".pdf"

DoCmd.OutputTo acOutputReport, "Channel Statements", acFormatPDF,
strFileName

Set rpt = Nothing

rs.MoveNext

Loop

rs.Close

Set rs = Nothing



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