Selecting a printer when printing a report using a command button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jinzuku
    New Member
    • Feb 2011
    • 12

    Selecting a printer when printing a report using a command button

    I’m trying to set up the printer button on my form, I want it to allow the user to select a printer when you try to print the report. I know that the code for this is
    Code:
    “DoCmd.RunCommand acCmdPrint”
    However, I don’t know where to fit it into the current code that automatically prints out that report:

    Code:
    Private Sub Print_Click()
    On Error GoTo Err_Print_Click
    
        Dim stDocName As String
    
        stDocName = "Result_Set"
        DoCmd.OpenReport stDocName, acNormal
        
    Exit_Print_Click:
        Exit Sub
    
    Err_Print_Click:
        MsgBox Err.Description
        Resume Exit_Print_Click
        
    End Sub
    Thanks

    Sunny
  • Lysander
    Recognized Expert Contributor
    • Apr 2007
    • 344

    #2
    Okay, I have not done this myself, but I thought it should be possible. Normally, a report is printed to the 'default' printer or you can open the report in preview mode, and the user can select the printer when they print the report.

    If you want the user to select a printer first, then obviously you will need a drop-down box listing all the possible printers and then use this property of the report that I have just come across

    (From the Access Help Files)

    PrtDevNames Property
    You can use the PrtDevNames property to set or return information about the printer selected in the Print dialog box for a form or report. Read/write Variant.

    It looks very complicated, the first part of the help file entry states

    "Remarks
    It is strongly recommended that you consult the Win32 Software Development Kit for complete documentation on the PrtDevMode, PrtDevNames, and PrtMip properties.

    The PrtDevNames property is a variable-length structure that mirrors the DEVNAMES structure defined in the Win32 Software Development Kit.

    Microsoft Access sets the PrtDevNames property when you make selections in the Printer section of the Print dialog box. You can also set the property by using Visual Basic.

    Microsoft Access uses the DEVNAMES structure to initialize the Print dialog box. When the user chooses OK to close the dialog box, information about the selected printer is returned by the PrtDevNames property.

    ©2003 Microsoft Corporation"

    I'm not sure why you want to do this, as the user can select and/or change the printer when they right click on the report and select print?

    Comment

    Working...