Hi All
I am using the following code to generate a series of reports based on a query (qryRptS). This is quite intensive on the Jet database engine as after producing reports for the first 9 records an error appears declaring that Access “cannot open any more tables”.
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("qryRptS")
qdf.Parameters("[Forms!frmCompany!StartDate]") = Forms!frmCompany!StartDate
qdf.Parameters("[Forms!frmCompany!EndDate]") = Forms!frmCompany!EndDate
Dim rst As DAO.Recordset
Set rst = qdf.OpenRecordset()
rst.MoveFirst
Do While rst.EOF = False
Dim filename As String
filename = rst.Fields("Trading Name") & " " & rst.Fields("Company ID")
filename = Replace(filename, "/", "-")
DoCmd.OpenReport "rptQryS", acViewReport, "", "[Company ID] = " & rst.Fields("Company ID"), acNormal
DoCmd.OutputTo acOutputReport, "rptQryS", "PDFFormat(*.pdf)", "\\HBSRV01\common\PROJECTS\Q1 Test\" & filename & ".pdf", False, "", , acExportQualityPrint
DoCmd.Close acReport, "rptQryS"
rst.MoveNext
Loop
End Function
A lot of the solutions to this problem involve simplifying queries/open tables. I’m not sure whether I would be able to do this to the extent that I would still be able to automate report generation for approx. 600 records.
However, I believe that if I close the recordset Access will clear the “tables memory”, i.e.:
rst.Close
Set rst = Nothing
qdf.Close
Set qdf = Nothing
Is there a clever way that I can get Access to remember which record it was on, so that I can close a recordset, reopen it and resume at the right record? Could I do this by setting a global variable, e.g. Global dbs as DAO.Database? If anyone has any thoughts on this then please let me know.
Thanks.
I am using the following code to generate a series of reports based on a query (qryRptS). This is quite intensive on the Jet database engine as after producing reports for the first 9 records an error appears declaring that Access “cannot open any more tables”.
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("qryRptS")
qdf.Parameters("[Forms!frmCompany!StartDate]") = Forms!frmCompany!StartDate
qdf.Parameters("[Forms!frmCompany!EndDate]") = Forms!frmCompany!EndDate
Dim rst As DAO.Recordset
Set rst = qdf.OpenRecordset()
rst.MoveFirst
Do While rst.EOF = False
Dim filename As String
filename = rst.Fields("Trading Name") & " " & rst.Fields("Company ID")
filename = Replace(filename, "/", "-")
DoCmd.OpenReport "rptQryS", acViewReport, "", "[Company ID] = " & rst.Fields("Company ID"), acNormal
DoCmd.OutputTo acOutputReport, "rptQryS", "PDFFormat(*.pdf)", "\\HBSRV01\common\PROJECTS\Q1 Test\" & filename & ".pdf", False, "", , acExportQualityPrint
DoCmd.Close acReport, "rptQryS"
rst.MoveNext
Loop
End Function
A lot of the solutions to this problem involve simplifying queries/open tables. I’m not sure whether I would be able to do this to the extent that I would still be able to automate report generation for approx. 600 records.
However, I believe that if I close the recordset Access will clear the “tables memory”, i.e.:
rst.Close
Set rst = Nothing
qdf.Close
Set qdf = Nothing
Is there a clever way that I can get Access to remember which record it was on, so that I can close a recordset, reopen it and resume at the right record? Could I do this by setting a global variable, e.g. Global dbs as DAO.Database? If anyone has any thoughts on this then please let me know.
Thanks.