General discussion

Locked

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

rst.MoveLast
rst.MoveFirst

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

rst.Close

Set rst = Nothing
Set db = Nothing

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

mod_TestPrint_Exit:
Exit Sub

mod_TestPrint_Err:
MsgBox Error$
Resume mod_TestPrint_Exit
End Sub

Thanks KB

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Software Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums