I am working with a donations database, and have developed a tax deductible receipt as a report.
The receipt prints both to paper and to a pdf in a folder. One of the problems is that there are several versions of the report, and so rather than create several reports, I coded the vba in the OnOpen event to make changes in the report according to data. Example: If a qualified donee gives a donation, then the receipt cannot claim to be an official receipt for income tax purposes, and instead says that it is an acknowledgement of gifts from the qualified donee. There are other changes to the visibility of certain labels depending on whether it is a reprint or a lost receipt, on whether it s a Gift in Kind, and on whether the gift contains an advantage received by the donor.

So the problem is that part of the code causes Error 3048, "Cannot open any more databases". I have done a lot of reading on it and found that something happens in Access 2016 which did not in previous versions. There have been various solutions given, none of which seem to work. Here is the code (sorry not sure how to put it in its own window thing). I removed some for simplicity and added 3 dots to show what was removed. The part where it errors out after 75 receipts are printed, is here at the command lline "DoCmd.OutputTo acOutputReport".

Dim db As DAO.Database
Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT * FROM BaseQry_ViewRcpts WHERE RcptSent = False ORDER BY RcptBatchID;")
If rst.RecordCount = 0 Then
MsgBox "There are no other unprinted receipts from those dates."
Exit Sub
End If
rst.MoveFirst
... /code to get receipt numbers for details when receipt opens/ ...
DoCmd.OpenReport "Donation_Rcpt", acViewReport, , , acHidden
Report_Donation_Rcpt.Requery
... /code to set name of PDF following/ ...
DoCmd.Close acReport, "Donation_Rcpt", acSaveNo
DoCmd.OutputTo acOutputReport, "Donation_Rcpt", acFormatPDF, "C:\Users\Camp.Director\Documents\New Tax ReceiptsTEST" & KeepName1 & ".pdf"
... / edit - update record to show as printed / ...




  • Some said there was an endless loop where things aren't being closed. I tried to solve it with that in mind, and it isn't that.
  • Some said that the issue was a programming error on attempts to DoCmd.OutputTo acOutputReport to a PDF and that there is an update for it. My version of Access uses volume licensing, and does not get those updates automatically, and I have failed at trying to find and install them manually.
  • One said that the report needs to be closed before the DoCmd.OutputTo acOutputReport occurs, which is why the last two lines are in that order. Unfortunately when I do it this way, all the changes made on the OnOpen and Requery events are lost and the report is no longer accurate. But it does solve the error. I ran over 100 receipts with no code errors occuring.


I think that somehow, when DoCmd.OutputTo acOutputReport runs internally with the report open, it somehow opens a file in memory and doesn't know how to close it. At one point I had used DoUntil rst.EOF - MoveNext - Loop to make the code smoother, and when I saw the possibility of endless open files, I chose to remove the loop, and find another way to go back until no more records showed up in the Select query. So after printing on paper and then on PDF, I closed the report, and then did a rst.close and db.close before going back to the top and starting over for the next unprinted record. It solved nothing. The only thing that does is to close the report before the PDF. But then my data is not accurately modifying the report.

Thanks for any help.
Gary