Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    LadyScot101 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    18

    Setting a specific printer as default using VBA in Access 2016

    I have a database that I have to add VBA code to a report to a specific printer. It's a multi-user database. It's trying to print to Adobe PDF and not the default printer. It goes through a print server on a network. Here is the code for the report. I added a line for the printer, but it doesn't work. Am I putting the path in correctly? I've never coded a path before.

    Private Sub PROCARD_NAVIGATION_Click()
    On Error GoTo Err_PROCARD_NAVIGATION_Click
    Dim stDocName As String
    Dim strCharacter As String
    stDocName = "ProCard Request"
    strCharacter = "ID"
    DoCmd.OpenReport stDocName, acPreview, , "ID =" & ID
    Set stDocName.Printer = "\\svpprintv01\wwtrmt-1" 'Added Specific Printer
    Exit_PROCARD_NAVIGATION_Click:
    Exit Sub
    Err_PROCARD_NAVIGATION_Click:
    MsgBox Err.Description
    Resume Exit_PROCARD_NAVIGATION_Click
    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I haven't use this , but you might read this article Printer Selection Utility by Allen Browne

    View the code at Code for Printer Selection Utility

  3. #3
    LadyScot101 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    18
    I saw that code ssanfu, but haven't a clue on how to change it to use with a network printer. Thanks though. I only have 2 reports, so I really don't need a huge code to add. I just need to adjust this report with the line that sets the printer. Anyone have experience with network print servers?

  4. #4
    LadyScot101 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    18
    Also, we do not want the user to choose the printer. We have it set where they click a button and it prints. So changing the Print Page will not work for us. It has to be done through the code.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    OK, I admit to not having much experience with this, but I don't see how you can assign the printer property to a string variable:
    Dim stDocName As String
    ...
    Set stDocName.Printer

    Try declaring the printer as an Object and assign it to the Application object (or maybe assign the printer object to a report object, but I haven't seen code for that).

    Dim prt As Printer
    Application.Printer = Application.Printers("\\svpprintv01\wwtrmt-1")
    'Print something

    When you ask if you're setting the path correctly, I'm more inclined to think that the actual printer name is what you want to use for the above, not its path. I suspect that is wwtrmt-1
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Here's how I change destination printer
    Code:
    Private Sub btnPrint_Click()
    'print to the color printer
    Dim strDefaultPrinter As String
    'load the current default printer into the variable strDefaultPrinter
    strDefaultPrinter = Application.Printer.DeviceName
    'switch to Konica printer for color printout
    Set Application.Printer = Application.Printers("\\your server name\your network printer name")
    'try to set printer for color - doesn't work, also tried API coding and that didn't work either
    ''Application.Printer.ColorMode = acPRCMColor
    ''Forms("ConcreteMixTools").Printer.ColorMode = acPRCMColor
    Me.Detail.BackColor = vbWhite
    DoCmd.PrintOut
    'change the printer back to the default printer
    Set Application.Printer = Application.Printers(strDefaultPrinter)
    End Sub
    Last edited by June7; 02-09-2018 at 03:29 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    @June7: can I ask why the string variable for the default printer name is set to be the application default? I've seen this before and don't understand the need for it. Not saying it's not required as it seems to be common. Just wondering why a string variable is made to hold a device name only to change it to whatever is required. If it were an object variable, I'd guess it's so that it can be initialized or something. Since it's not, I have no clue.

    by this
    load the current default printer
    you really mean the default printer name, not the printer as an object, correct?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Micron, you save the default printer name so that you can change back to that printer after printing to the newly selected printer.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    I set a string variable to the user's current default printer then I change their default printer for the immediate printout then change back to their original default printer. In the example code I am actually printing a form, not a report. It's the only way I could figure how to accomplish targeting a printer.

    Following may be possible. Can't remember if I ever tried it for form or report. I might have to do some testing.

    Reports("rptMyReport").Printer = Application.Printers("\\your server name\your network printer name")


    I have other code that sets duplexing output if user default printer has that functionality and that is printing a report.
    Last edited by June7; 02-09-2018 at 03:39 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I have other code that sets duplexing output if user default printer has that functionality and that is printing a report.
    And when you are switching printers with code, the printing defaults are not universal. As well as duplexing, you can set things such as orientation for the newly selected printer/report.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Yes, I had to find code that would allow me to list connected printers and their properties. We got new printers and had to change code and lost some capability. Code targets paper tray and would not work with one of the new printers.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    LadyScot101 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    18
    June7, where to I enter this at? I have code already in the "Click" to open and run the report. I tried to enter this in the "On Enter", but it errored out. This is the code I entered:

    Private Sub PROCARD_NAVIGATION_Enter()
    Dim strDefaultPrinter As String
    strDefaultPrinter = Application.Printer.DeviceName
    Set Application.Printer = Application.Printers("\\svpprintv01\wwtrmt-1")
    DoCmd.PrintOut

    Set Application.Printer = Application.Printers(strDefaultPrinter)
    End Sub


    Isn't there a way to enter it into the original "Click" code that opens the report?

  13. #13
    LadyScot101 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    18
    Davegri, we are printing to a multi-function copier. It's all one sided reports and in b&w. Nothing fancy. So I don't need any settings code, just a code to set the default to it.

  14. #14
    LadyScot101 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    18
    June7, If I put the code in the button that opens the form in the database, then would I replace Form where you have Reports? and is rptMyReport the name of the form or is that a vba code? I'm majorly new at this, so I'm not sure sometimes whether I'm replacing names in the examples or not.

  15. #15
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    The below will work to print to a PDF printer. Substitute your printer name.
    Code:
    Private Sub PROCARD_NAVIGATION_Click()
    On Error GoTo Err_PROCARD_NAVIGATION_Click
    Dim stDocName As String
    Dim strCharacter As String
    stDocName = "ProCard Request"
    strCharacter = "ID"
    DoCmd.OpenReport stDocName, acPreview, , "ID =" & ID
    
    
    Reports(stDocName).Printer = Application.Printers("Microsoft Print to PDF")
    
    
    'Set stDocName.Printer = "\\svpprintv01\wwtrmt-1" 'Added Specific Printer
    Exit_PROCARD_NAVIGATION_Click:
    Exit Sub
    Err_PROCARD_NAVIGATION_Click:
    MsgBox Err.Description
    Resume Exit_PROCARD_NAVIGATION_Click
    End Sub

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Use VBA to Rename a Default Ribbon Tab in Access 2016
    By jeffreymiller in forum Programming
    Replies: 1
    Last Post: 11-18-2016, 08:43 AM
  2. Set Default Printer
    By jo15765 in forum Modules
    Replies: 5
    Last Post: 02-18-2016, 07:05 AM
  3. Access 2016 Default Value Issue
    By breakingme10 in forum Forms
    Replies: 7
    Last Post: 09-23-2015, 10:07 AM
  4. Setting Default Printer Properties with VBA Cocde
    By EddieN1 in forum Programming
    Replies: 2
    Last Post: 12-04-2014, 11:02 AM
  5. Replies: 3
    Last Post: 02-25-2014, 11:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums