locked
Access Runtime 2010 intermittently CRASHED in application.printers RRS feed

  • Question

  • I have NO problem in changing the Printer in 2003 ADP (connected to SQL 2005) working in Access 2010 Full Version  but when I run the ADP/ADE file into another Server (Windows Server 2003 SP2) with Access Runtime 2010 I got intermittent error and the application shutdown.

    I tried different codes from different forums on how to change the printer but it intermittenly crashed in "application.printers"

    Here are the codes I tried:

    VERSION 1:===============================
    Dim rpt As Report
    DoCmd.OpenReport "reportName", acViewPreview, , ,acHidden
    Set rpt = Reports("reportName")
    Set rpt.Printer = Application.Printers(strPrinterName)
    DoCmd.OpenReport "reportName", acViewNormal
    DoCmd.Close acReport, "reportName"

    VERSION 2:===============================
    strDefaultPrt = Application.Printer.DeviceName
    Set Application.Printer = Application.Printers(strPrinterName)
    DoCmd.OpenReport "reportName", acViewNormal
    Set Application.Printer = Application.Printers(strDefaultPrt )

    VERSION 3:====================
    strDefaultPrinter = Application.Printer.DeviceName
    Call SetSpecificPrinter(strPrinterName)
    DoCmd.OpenReport "reportName", acViewNormal
    Call SetSpecificPrinter(strDefaultPrinter)


    Sub SetSpecificPrinter(tmpPrinterName)
    Dim prn As Printer
    Dim blnPrinterSet As Boolean

    For Each prn In Application.Printers

       If prn.DeviceName = tmpPrinterName Then

           Set Application.Printer = prn
          
           blnPrinterSet = True
           Exit For
       End If
    Next prn

        If Not blnPrinterSet Then MsgBox "Invoice Printer NOT found.", vbCritical

    Set prn = Nothing

    End Sub

    ===============

    Access 2010 crashed everytime it sees "application.printers"

    Here's the error I got, or sometimes no error message at all:

    "The exception unknown software exception (0xc0000417) occured in the application at location 0x785520f0"

    When I hit OK button, application will be close.

    Need suggestions on how to fix this intermittent error.... Please...

    Thanks in advance!

    Thursday, October 27, 2011 1:10 PM

Answers

  • I placed the function before opening the report.

    I also tried opening the report in "Hidden" view and then change the report printer and then open the report again in a "Normal" view.

    But still have that error.

    Anyway, I got it to work. I found different code in changing the printer without using "application.printers" so far no problem yet. Hopefully this will be the permanent fix. Thanks a lot for all your help!

    Here's the code for the benefits of others as well;

    Option Compare Database
    Option Explicit
    Public Declare Function SetDefaultPrinter Lib "winspool.drv" _
    Alias "SetDefaultPrinterA" (ByVal pszPrinter As String) As Long


    'Inside the function where the report opens==========

    dim strInvoicePrinter as string
    dim strDefPrt as string

    'set the invoice printer
    strInvoicePrinter = "invoice_prt"

    'get the default printer
    strDefPrt = Application.Printer.DeviceName
                   
    'change the printer to be Invoice Printer
    SetDefaultPrinter strInvoicePrinter
                   
    DoEvents
                   
    'print the report
    DoCmd.OpenReport "report_name", acViewNormal
                   
    DoEvents
                   
    'set the printer back to Default Printer
    SetDefaultPrinter strDefPrt

    • Proposed as answer by danishani Tuesday, November 1, 2011 6:11 PM
    • Marked as answer by danishani Wednesday, January 11, 2012 8:27 PM
    Tuesday, November 1, 2011 6:05 PM

All replies

  • I am not sure what causes the crashes, but you might add Error handling in the code, and then see what error message comes up.

    For example if there is no printer installed on a Machine it will raise an Run-time error '2205': The default printer driver isn't setup correctly.

     

    So without error handling, especially in Runtime, access will crash.

     

    See also for more reference on how to set printers in Reports etc. below article, gives some good inside:

    http://msdn.microsoft.com/en-us/library/aa139946(v=office.10).aspx

     

    My 2 cts...

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    • Edited by danishani Thursday, October 27, 2011 10:35 PM add link
    Thursday, October 27, 2011 10:31 PM
  • Thanks for your response Daniel.

    I already tried to put Error Handler and it didnt catch the error. I also tried On error resume next it didnt work as well.. :(

    I also put checking of all the printers in my server and match it to the printer that I want to assign to my report, it works fine. But it will crashed when the time I assign the printer to the report or once the compiler sees the "Application.Printers"

      

    Friday, October 28, 2011 12:56 PM
  • Hmm strange indeed, which Event are you placing the code?

     

    See the notice in the MSDN article mentioned above:

    Important   While Access will allow you to change a report's printer settings when a report is opened from event procedure code running in the report's Activate event, you should not do so. Access doesn't currently have the ability to redo the layout for a report if those settings are changed from the events that are fired when you open a report. For this reason, attempting to change a report's printer settings from all other report events, such as the Open event, will return a run-time error. To change a report's printer settings, you should use code running in a separate form or module that opens the report in Print Preview or Design View before changing printer settings and printing the report.

        You also cannot set form or report printer properties after printing has started. If you try to do so, the following run-time error is displayed:

        Run-time error '2191': You can't set the Printer property after printing has started.

     

    Anyway, another utily which works in Runtime, you can find in here, by Allen Browne:

    http://allenbrowne.com/AppPrintMgt.html

     

    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Friday, October 28, 2011 7:16 PM
  • Another thing, what came to mind, is you mind to a Decompile of your database, and see if that resolves your problem:

    http://www.fmsinc.com/microsoftaccess/performance/decompile.asp

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Monday, October 31, 2011 10:50 PM
  • I placed the function before opening the report.

    I also tried opening the report in "Hidden" view and then change the report printer and then open the report again in a "Normal" view.

    But still have that error.

    Anyway, I got it to work. I found different code in changing the printer without using "application.printers" so far no problem yet. Hopefully this will be the permanent fix. Thanks a lot for all your help!

    Here's the code for the benefits of others as well;

    Option Compare Database
    Option Explicit
    Public Declare Function SetDefaultPrinter Lib "winspool.drv" _
    Alias "SetDefaultPrinterA" (ByVal pszPrinter As String) As Long


    'Inside the function where the report opens==========

    dim strInvoicePrinter as string
    dim strDefPrt as string

    'set the invoice printer
    strInvoicePrinter = "invoice_prt"

    'get the default printer
    strDefPrt = Application.Printer.DeviceName
                   
    'change the printer to be Invoice Printer
    SetDefaultPrinter strInvoicePrinter
                   
    DoEvents
                   
    'print the report
    DoCmd.OpenReport "report_name", acViewNormal
                   
    DoEvents
                   
    'set the printer back to Default Printer
    SetDefaultPrinter strDefPrt

    • Proposed as answer by danishani Tuesday, November 1, 2011 6:11 PM
    • Marked as answer by danishani Wednesday, January 11, 2012 8:27 PM
    Tuesday, November 1, 2011 6:05 PM
  • Ah ok, glad you got it solved! :)

     

    Cheers,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, November 1, 2011 6:11 PM