Solved

Automatically Print report to specific printer but did not set it back to the default print

Posted on 2012-03-12
4
402 Views
Last Modified: 2012-03-12
Hi Experts,
I was just too quick to close my last question before I notice this problem.  (My last question was "Automatically Print Report to a specific Printer") and Helen Feddema and Dodahd gave me the answer which works to print to the specific print but I notice that after I print this specific report to the specific printer, and tried to print other report, it seems the system did not reset the second report that I tried to print back to my default printer.  Below is all the code that I'm using in the program:

In the Module is :
Public Sub PrintToSpecificPrinter(strPrinter As String, strReport As String)
'Created by Helen Feddema 12-Feb-2010
'Last modified by Helen Feddema 12-Feb-2010

On Error GoTo ErrorHandler

   Dim prtCurrent As Printer
   Dim prtDefault As Printer
   'Dim strPrinter As String
   'Save current default printer
   Set prtDefault = Application.Printer
   Debug.Print "Current default printer: " & prtDefault.DeviceName
   'Select a specific printer as new default printer
   Application.Printer = Printers(strPrinter)
   
   'Print the report
   DoCmd.OpenReport strReport
   
   'Set printer back to former default printer
   Application.Printer = prtDefault
     
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & _
      Err.DESCRIPTION
   Resume ErrorHandlerExit

End Sub


In my OnClick Event is :
Private Sub Command18_Click()
On Error GoTo Err_Command18_Click
    Dim stdocname As String
    Dim stCriteria As String
    Dim strReport As String
    Dim strPrinter As String
    strPrinter = strdocname
    strPrinter = "AA_ABCE_CL4650_122"
   
    Form_frmPrintedFormsAll.HoldAnyData = Me.NameEntered
    Form_frmPrintedFormsAll.Note = Me.AddNote
    Form_frmPrintedFormsAll.RecordNo = Me.RecordNo
   
    If IsNull(NameEntered) Or IsNull(RecordNo) Then
       MsgBox "Please enter all informations before proceeding."
       Exit Sub
    Else
       stCriteria = "CHRecord = '" & Me.RecordNo & "'"
       strReport = "rptFileRequest"
       Call PrintToSpecificPrinter(strPrinter, strReport)
    End If

   
Exit_Command18_Click:
    DoCmd.Close acForm, "frmParmFileRequest"
    Exit Sub

Err_Command18_Click:
    MsgBox Err.DESCRIPTION
    Resume Exit_Command18_Click
   
End Sub

My default printer is "AA_ACEE_CL4530_135" but it prints everythig to printer "AA_ABCE_CL4650_122" after I print that specific report.  Can any one help?

Thanks
0
Comment
Question by:jodstrr2
  • 2
  • 2
4 Comments
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
ID: 37709972
Are you printing the other reports in the interface or in code?  Try putting a Debug.Print statement in the code after the printer is reset to the default, and see what you get.

Also, you could specifically set the default printer to the correct printer name in your Click event code, after printing to the specific printer.
0
 

Author Comment

by:jodstrr2
ID: 37710097
Hi Helen,
Can you give me a little bit more details base on my code above? I'm kind of confusse now.
0
 

Author Comment

by:jodstrr2
ID: 37710803
Hi Helen,
Thanks for your suggested.  Yes, it works after I changes like this:
   Application.Printer = prtDefault
   Debug.Print "Current default printer: " & prtDefault.DeviceName

Thanks
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 37710838
It could be that the default printer was changed somehow (apart from the code), but you can always explicitly set it back to what it should be.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now