Link to home
Start Free TrialLog in
Avatar of jodstrr2
jodstrr2

asked on

Automatically print report from a specific printer

Hi Experts,
I have users that assigned to their own defaul printer (every user has different printer IP), however, I have a report that I would like all the users can print from one specific printer (not the one that they assigned to) and not display the printer dialog for them to select that specific printer, when they click ok button on the form to print the report, the report will automatically print from that specific printer.  ( I will set the report as DoCmd.OpenReport stdocname, acNormal).  Does anyone have any idea or any code I can use?  ( I used  DoCmd.RunCommand acCmdPrint but this is for pop up the printer dialog for the user to select the printer, which I don't want to do that because I in that cases, I have to install that specific printer on each user's computer)

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jodstrr2
jodstrr2

ASKER

where I can put this code in?  Modules? or on the form which will print the report?
here is my code from the form

Private Sub Command18_Click()
On Error GoTo Err_Command18_Click

    Dim stdocname As String
    Dim stCriteria As String

    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 & "'"
       stdocname = "rptRequest"
       DoCmd.OpenReport stdocname, acPreview
       'DoCmd.RunCommand acCmdPrint

       'Form_frmParmFileRequest.Visible = False
    End If
   
Exit_Command18_Click:
    DoCmd.Close acForm, "frmParmForm"
    Exit Sub

Err_Command18_Click:
    MsgBox Err.DESCRIPTION
    Resume Exit_Command18_Click
   
End Sub
If you use Page Setup for a Form or Report in Access, you can specify a specific printer.  Without specifying, the print goes to the default printer for the workstation.

However, when specified, the print goes to the specific printer  

You may not need to write code.
Hi Dodahs,
If I use the page setup for the report then I have to install the specific printer on every user's computer and we have more than 100 users that's the reason we don't want to install the printer on every user's computer instead have the code on the form to do that if it's possible.
If you dont want to get into scripting to verify users you could use a bit of freeware call event comb.  very simple to use, just add the name of the server that the print queues are on and set the event ids for print events and this will output to an easy to read text file.
Identify the value for your specific printer.

Once you have that, use Helen's subroutine code to print your report to a specifit printer

Save her first code as a module in Access.

Call the subroutine with the name of the printer, a comma, and the name of the report:
   Call PrintToSpecificPrinter("MyPrinter", "MyReport")
as part of the OnClick code for the button.
ok, DoDahd,
I just copy Helen's first code to a module, but I'm not quite understand this
"Call the subroutine with the name of the printer, a comma, and the name of the report:
   Call PrintToSpecificPrinter("MyPrinter", "MyReport")"

here is my code now but I got an error message ""Argument Not Optional".  I knew I did something wrong but just don't know where.

Private Sub Command18_Click()
On Error GoTo Err_Command18_Click

    Dim stdocname As String
    Dim stCriteria As String

    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 & "'"
       stdocname = "rptRequest"
       DoCmd.OpenReport stdocname, acNormal
       PrintToSpecificPrinter
    End If
   
Exit_Command18_Click:
    DoCmd.Close acForm, "frmParmForm"
    Exit Sub

Err_Command18_Click:
    MsgBox Err.DESCRIPTION
    Resume Exit_Command18_Click
   
End Sub
Hi dinsj,
I'm not quite understand how to use your suggest.
you can download it from here:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=18465

once in the software you can add a server or multiple servers that have the required print queues then add the print queue event id or just certain type of events

you can use it for more then just print event capturing
jodstrr2

To use the code within your code, in place of
       DoCmd.OpenReport stdocname, acNormal
       PrintToSpecificPrinter

use
       stPrintSpecific =  "printer name"
       Call PrintToSpecificPrinterst(stPrintSpecific , stdocname)

after you replace your special printer name for "printer name"
Hi Dodahd,
Do I need to change anything from Helen's first code or just save as is in the module?  
"Debug.Print "Current default printer: " & prtDefault.DeviceName"  do I need to change the "Device Name" to the printer name?  thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Dodahd,
Here is the my whole code,
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 & "'"
       stdocname = "rptFileRequest"
       Call PrintToSpecificPrinter(strPrinter, strReport)


       'DoCmd.OpenReport stdocname, acNormal
       'PrintToSpecificPrinter
       'Form_frmParmFileRequest.Visible = False
    End If

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

Err_Command18_Click:
    MsgBox Err.DESCRIPTION
    Resume Exit_Command18_Click
   
End Sub

But I got an error message when I tried to print
Error No: 2497; Description: The action or method requires a report name argument.

What did I do wrong?

Thanks
I figure it out the problem.
Hi Dodahd,
I figure out the problem, it's
 stdocname = "rptFileRequest" should be strReport = "rptFileRequest"

Thanks
Thanks so much for Helen and Dodahd's huge help.  Thanks again