cricketbird
Registered User.
- Local time
- Today, 08:36
- Joined
- Jun 17, 2013
- Messages
- 108
I am trying to loop through all the records from a query and print one PDF report for each line of the query results. The data is located on a networked backend.
The code below generates the dreaded "cannot open any more databases" error after the first report. I was told each report opened creates connections to the backend. I thought I could maybe fix this by closing the report after each run. Indeed, after adding in the "DoCmd.Close acReport" line below, it now will generate about 25 reports before throwing that same error. I have hundreds of reports that need to run, though.
Is there something I can do (beyond closing the report) to help close connections once they aren't needed?
I am running MS Access Version 2301 (build 16026.20238 Click-to-Run) with no options in my corporate environment to change/downgrade/upgrade versions. Based on what I've read about the "cannot open any more databases" error, I've added the front and back ends to my "trusted locations". That has not made any noticeable differences.
The code below generates the dreaded "cannot open any more databases" error after the first report. I was told each report opened creates connections to the backend. I thought I could maybe fix this by closing the report after each run. Indeed, after adding in the "DoCmd.Close acReport" line below, it now will generate about 25 reports before throwing that same error. I have hundreds of reports that need to run, though.
Is there something I can do (beyond closing the report) to help close connections once they aren't needed?
Code:
Set MyRs = CurrentDb.OpenRecordset("BackupCardListQry")
With MyRs
.MoveFirst
Do While Not .EOF
fileName = !Name & " - Card #" & !CardID & " - " & todayDate & ".pdf"
DoCmd.OpenReport "RptPERMANENT_CARD", acViewReport, , "[CardID] = " & !CardID
DoCmd.OutputTo acOutputReport, , acFormatPDF, thisLoc & fileName
DoCmd.Close acReport, "RptPERMANENT_CARD"
.MoveNext
Loop
End With
I am running MS Access Version 2301 (build 16026.20238 Click-to-Run) with no options in my corporate environment to change/downgrade/upgrade versions. Based on what I've read about the "cannot open any more databases" error, I've added the front and back ends to my "trusted locations". That has not made any noticeable differences.