How to print form to a network printer?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bknabl
    New Member
    • May 2010
    • 19

    How to print form to a network printer?

    I am having difficulty finding the proper code to print to a network (non-default) printer.

    I have it currently set to print on a default printer using this code (created in wizard):

    Code:
    Private Sub cmdPrint_Click()
    On Error GoTo Err_cmdPrint_Click
    
        Dim stDocName As String
        
        stDocName = "frmPrint"
        DoCmd.OpenReport stDocName, acNormal
    This program is going to be accessed by multiple users throughout the plant and I need the form to be sent to only one printer.

    This is being created in MS Access 2003. Thanks again guys!
  • Jim Doherty
    Recognized Expert Contributor
    • Aug 2007
    • 897

    #2
    Originally posted by bknabl
    I am having difficulty finding the proper code to print to a network (non-default) printer.

    I have it currently set to print on a default printer using this code (created in wizard):

    Code:
    Private Sub cmdPrint_Click()
    On Error GoTo Err_cmdPrint_Click
    
        Dim stDocName As String
        
        stDocName = "frmPrint"
        DoCmd.OpenReport stDocName, acNormal
    This program is going to be accessed by multiple users throughout the plant and I need the form to be sent to only one printer.

    This is being created in MS Access 2003. Thanks again guys!
    Assuming you know the name of the specific printer in the printers collection

    Code:
    DoCmd.OpenReport stDocName, acViewNormal
    Reports(stDocName).Printer = "YourPrinterName"

    Comment

    • bknabl
      New Member
      • May 2010
      • 19

      #3
      My printer name that I am trying to use has spacing in the name of it.
      Code:
      Reports(stDocName).Printer = HP deskjet 6122 series
      obviously access does not like that. How should I fix that?

      Comment

      • bknabl
        New Member
        • May 2010
        • 19

        #4
        Bumping so this thread doesn't get overlooked.

        Comment

        • Jim Doherty
          Recognized Expert Contributor
          • Aug 2007
          • 897

          #5
          Originally posted by bknabl
          My printer name that I am trying to use has spacing in the name of it.
          Code:
          Reports(stDocName).Printer = HP deskjet 6122 series
          obviously access does not like that. How should I fix that?
          Sorry I obviously missed response in my list. The name of any printer should be wrapped in speechmarks "" given its a string but further to it anyway the following code identifies which printers you will have available to you so you can make sure it is listed as available to print too then once you have its name as defined you can hard code it in if you want but remember to wrap it in speechmarks.

          My advice to you as an aside, would be to throw the name of the printer you want to a one row table so that if the printer goes belly up some day you merely alter the name of any new or replacement printer in the one row lookup table. That way you don't have to revisit your code and all you need is the Dlookup function to look up this name and use its return value as the argument for the printer name.

          Code:
          Dim prt As Access.Printer
             Dim i As Integer
             i = 0
             For Each prtr In Application.Printers
                Debug.Print The Available Printers is:" & prtr.DeviceName
                If prtr.DeviceName = Application.Printer.DeviceName Then
                   Debug.Print "The default printer is listed is listed (" & i & ") " &prt.DeviceName
                End If
                i = i + 1
             Next
          End Sub
          The command line you need (if it matches one in the defined list of printer names) will be

          Code:
          Reports(stDocName).Printer = "HP deskjet 6122 series"
          Regards

          Comment

          Working...