General discussion


Access 2007 VBA Do While Loop Repeats Output

By kb_whitmore ·
I have a control table with various reports that I want to output to PDF. Using Access 2007 VBA, I wrote a Do While Loop to go through the local table (30 records) and print out each report. The problem is that is just prints out the same report 30 times. Can anyone tell me what is wrong with this code? I am very frustrated and would appreciate some advice.

Sub mod_TestPrint()
On Error GoTo mod_TestPrint_Err

Dim dbs As DAO.Database, rst As DAO.Recordset, StrRptName As String, strPath As String

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("TEmailControlPrc", dbOpenTable, dbReadOnly)

StrRptName = rst!ReportName
strPath = rst!FilePath & Format(Date, "mmmm") & rst!FileName


Do While Not rst.EOF
DoCmd.OutputTo acOutputReport, StrRptName, "PDFFormat(*.pdf)", strPath, False, "", 0, acExportQualityPrint


Set rst = Nothing
Set db = Nothing

MsgBox Prompt:="Pricing Reports have been saved to pdf."

Exit Sub

MsgBox Error$
Resume mod_TestPrint_Exit
End Sub

Thanks KB

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Related Discussions

Related Forums