Change Printer for Report in Access

ramez75

Registered User.
Local time
Today, 07:45
Joined
Dec 23, 2008
Messages
181
Hi,

I have been working on this for few days but I dont seem to figure out what I am doing wrong and why I cant get it to work.

When the user opens the report (rptSchedule) a form (frmPrintEmailPopup) is opened infront of the report. The form has 3 buttons: Email (works with no issues), Print (Works with default printer) and Close.

I want to allow users when they press the "Print" button to get the chnage printer dialogue box to change the printer. Currently the report is setup to print from my desk printer. For security and disabled the right mouse click in the database.

Below is the code I have on the event: On Click of the frmPrintEmailPopup.

Code:
Private Sub Print_Click()
    On Error GoTo Err_Print_Click

    'Opens print dialog for current screen:
    DoCmd.RunCommand acCmdPrint
    
    DoCmd.OpenReport Me.reportName
    MsgBox "Print Complete"
Exit_Print_Click:
    Exit Sub
Err_Print_Click:
    ' If action was cancelled by the user, don't display an error message.
    Const conErrDoCmdCancelled = 2501
    If (Err = conErrDoCmdCancelled) Then
        Resume Exit_Print_Click
    Else
        MsgBox Err.Description
        Resume Exit_Print_Click
    End If
   
End Sub


Below is the code I have on the event: On Click of the rptSchedule.

Code:
Option Compare Database
Private Sub Report_Open(Cancel As Integer)
    DoCmd.OpenForm "frmPrintEmailPopup"
    Forms!frmPrintEmailPopup!reportName = Me.Report.Name
End Sub

Currently with the above when the report is opened and the "Print" button is clicked on the frmPrintEmailPopup form the printer change dialogue box is opened but it prints only the image of the form and the report prints on my desk printer.

I will appreciate if someone could look at what I have and tell me what I am doing wrong or how to correct it

Thanks in advance

RB
 
I use the following code to select a specific reporter printer which is not necessarily the Windows default printer.

Code:
  'Get current default printer
  strDefaultPrinter = Application.Printer.DeviceName

  'Switch to the printer this applicaiton is suppose to use
  Set Application.Printer = Application.Printers(strBarcodePrinter)

  'Open the report... Top line is for dev testing / bottom line is for production
  DoCmd.OpenReport "rptqryeditorder", acViewPreview, , , acWindowNormal
  'DoCmd.OpenReport "rptqryeditorder", acViewNormal, , , acWindowNormal
  MsgBox "Printer " & strBarcodePrinter & " should have received the report.", vbOKOnly + vbExclamation, "Document Printed"

  'Switch the printer back to the default
  Set Application.Printer = Application.Printers(strDefaultPrinter)
The format of the string the print queue is set to is the UNC path to the printer, Example:

Code:
\\printserver\printqueue
 
Thanks mdlueck

So do I replace my code with yours. I want Users to be able to chose printers that are located in their departments. Your code seems to set the printer to "strBarcodePrinter". In my case I dont know what the printer names are. So what way I should do to enable the user to chose the printer.

I thought "DoCmd.RunCommand acCmdPrint" should work but it prints the image of the form and not the report
 
It has to be something simple.

the command "DoCmd.RunCommand acCmdPrint" is opening the dialogue box. I am chosing the printer but its not printing the report but it prints the image of the form but the report still prints on the default printer
 
My code sample changes the printer to one defined by application administrators, to print specific reports to. My code saves off what the current printer was, and sets it back after it sends the report to the printer.

You would have to come up with your own printer selection logic / dialog box.

The format the change printer code expects to be handed is UNC format name of the print queue.

That is as much as I can help you.
 

Users who are viewing this thread

Back
Top Bottom