when working with some 30 test records all is fine. I filter a recordset and create PDF files. When using the production data, the filter returns 100 records and creates SOME PDFs - varying from 1 to 7 to 20, but not all.
It just stops working, the task manager shows no activity any more. I only think there is an issue with objects not closed but I have no idea
Any hints?
thx
Dim rst As DAO.Recordset
Dim rstFiltered As DAO.Recordset
Dim rpt As Access.Report
dim strRptName As String
Dim sFolder As String 'the output folder with PDFs
Dim sFilePDF As String 'complete path of the *.PDF file
Const gcAppQry53312 as string = "Qry53312"
Set rst = CurrentDb.OpenRecordset(gcAppQry53312, dbOpenSnapshot)
var_rpt_WHERE = ....
rst.Filter = var_rpt_WHERE
sFolder = "C:\test\"
Set rstFiltered = rst.OpenRecordset(dbOpenSnapshot)
With rstFiltered
.MoveFirst
Do While Not .EOF
DoCmd.OpenReport ReportName:=strRptName _
, View:=acViewPreview _
, Filtername:="" _
, WhereCondition:="" _
, WindowMode:=acHidden
Set rpt = Reports(strRptName).Report
sFilePDF = ![NVNameID] & ".pdf"
sFilePDF = sFolder & sFilePDF
'=*=*=*=*
DoEvents
'=*=*=*=*
DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, sFilePDF, , , , acExportQualityPrint
'-- 13. finis
Set rpt = Nothing
DoCmd.Close acReport, strRptName
.MoveNext
Loop
End With
If Not rpt Is Nothing Then Set rpt = Nothing
If Not rstFiltered Is Nothing Then
rstFiltered.Close
Set rstFiltered = Nothing
End If
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
CodePudding user response:
instead of using .EOF, if you have a way to dynamically identify the document count you need at any given time you could create this value as a dimention then loop on an incranemtal counter within the loop (also a dimention) vs the dynamically identify document count, this should work.
CodePudding user response:
Try to reduce this to the essential part:
Do While Not .EOF
sFilePDF = ![NVNameID] & ".pdf"
sFilePDF = sFolder & sFilePDF
DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, sFilePDF, False, , , acExportQualityPrint
.MoveNext
Loop