Print Report to pdf for each record in recordset

W

Wayne

I've run into an issue I can't find an answer for. This code below is
supposed to enumerate thru a recordset and print the report to separate pdf
document's. If I remove the open report statement and do a debug.print it
will display all of the file names it would be creating however, when I use
the open report command the code stops executing after the first report is
printed. Any help would be greatly appreciated.

Thank, Wayne

Private Sub cmd2_Click()
Dim DB As DAO.Database, T As DAO.TableDef, _
rst As DAO.Recordset, stDocName As String, _
stLinkCriteria As String, JobCode As String, Title As String, _
lngRetVal As Long, strFileName As String, strSQL As String

stDocName = "rptDescriptions"
strSQL = "SELECT RequestNumber, JobCode, PJobTitle" _
& " FROM tblDescriptions" _
& " WHERE (((Len([JobCode])) = 6))" _
& " ORDER BY tblDescriptions.RequestNumber;"

Set DB = CurrentDb()
Set rst = DB.OpenRecordset(strSQL)
rst.MoveFirst
Do While Not rst.EOF
stLinkCriteria = "[RequestNumber]=" & rst![RequestNumber]
JobCode = rst![JobCode]
Title = rst![PJobTitle]
strFileName = Title & "." & JobCode & ".pdf"
lngRetVal = SetRegValue _
("HKEY_Current_User", "Software\Adobe\Acrobat PDFWriter", "PDFFileName", _
"C:\Documents and Settings\" & fosusername & "\Local Settings\Temp\" &
strFileName)

DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
rst.MoveNext
Loop
rst.Close
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