Printing crashes Application

Eljefegeneo

Still trying to learn
Local time
Today, 06:27
Joined
Jan 10, 2011
Messages
902
Using Access 2010.

I have the following code to print out three versions of a contract report, differing only in footer on the report set by the OpenArgs. The OpenArgs to set the footer for each copy of the contract are set as A, B and C. They are set in the OnLoad of the report.

The code I use is:

Code:
    ' --- Note that there are OpenArgs to set the footer for each contract
   
  DoCmd.OpenReport MyRpt, acViewPreview, , "[SequenceNumber] = " & Me![SequenceNumber], , "A"
  'Saves the report as a PDF file in the proper directory, only needed once.
                 DoCmd.OutputTo acOutputReport, MyRpt, acFormatPDF, MyPath & MyFileName, False
                                               DoCmd.PrintOut
                                                              DoCmd.Close acReport, MyRpt
   
  DoCmd.OpenReport MyRpt, acViewPreview, , "[SequenceNumber] = " & Me![SequenceNumber], , "B"
                 DoCmd.PrintOut
                                DoCmd.Close acReport, MyRpt
   
  DoCmd.OpenReport MyRpt, acViewPreview, , "[SequenceNumber] = " & Me![SequenceNumber], , "C"
                  DoCmd.PrintOut
                                DoCmd.Close acReport, MyRpt
               End If
The problem is that running code this the application stops working (non-responding) and then crashes. Strangely enough, on my home computer not connected to any network although I have split the DB, it works OK, but on my office computer where the back end is on the server, it crashes. I have the same amount of memory, 4 GM on each, so that might not be it. So it might be that the server connection is not fast enough for the code to run without hanging up.

What I would like to know is if my code above is optimal or could it be improved. Or what else might be causing the problem.
 
In which code line does it crashes?
 
or perhaps your server data contains a null or other inconsistent value causing the issue which you do not have in your home data
 
The crash occurs after the first report is sent to the printer. Somewhere after the second report is sent, the dreaded "program is not responding" error occurs. NO reports are printed. The data is exactly the same home and office.

I tried to break up the code by inserting a message box to pause each report being sent to the printer and it works fine.
 
You say the problem occurs after the first report. Is it possible the comment "only needed once." isn't true?
 
No, only the fist copy of the report is saved. Then all three are printed.
 
And just to be sure, I tested it again here at home and it works fine. Used the exact same data as is on the office computer. Same record to be saved and printed.
 
Another one solved, at least I think I found the problem and solution. I was opening up the report, saving the first copy as a PDF file and then printing it and then closing it. If I changed the order, that is, printed it first and then saved it, the problem went away.

Why this should make a difference in unknown to me, as the first sequence of code worked on my home computer but not on the one at work.

But I am "moving on". Thanks to those that tried to help me.
 

Users who are viewing this thread

Back
Top Bottom