Results 1 to 7 of 7
  1. #1
    chromachem is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    49

    Reset to default printer after printing labels

    We have looked at this issue on this forum and elsewhere. Seems to be a common problem with no solution that we are able to find. Should be simple.
    No problem switching from the default printer to the label printer and printing a label. Big problem switching back to default printer after printing a label.


    If we comment out the line that actually prints labels, the printers switch back and forth with no problem.

    If we actually print a label (DoCmd.RunCommand acCmdPrint), the code to select the default printer doesn't work. No errors. Printing the label "freezes" the label printer as the default printer.

    Code:
    Public Function PrintLabels()
    Dim prtDefaultPrinter As Printer
    strReport = Application.CurrentObjectName
    
    
    Select Case strReport
    
    
    Case Is = "tblLabels"
       
       Set prtDefaultPrinter = Application.Printer  ' set default printer
       Set Application.Printer = Application.Printers("Brother QL-570 LE") 'swith to label printer
       DoCmd.OpenReport "rptLabels", acViewPreview
       DoCmd.RunCommand acCmdPrint 'prints to label printer
       Set Application.Printer = prtDefaultPrinter ' DOES NOT RESET TO default printer
       DoCmd.Close acReport, "rptLabels", acSaveNo
         
    End Select
    
    
    End Function

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Not really sure, but first thing I'd try is dropping the acSaveNo parameter.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    chromachem is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    49
    Removing acSaveNo made no difference. Thanks for looking.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Try dimming the
    Dim prtDefaultPrinter As String

    In general I would have a
    debug.print strReport during testing to ensure it contained what you expect.

    I recommend Option Explicit to require dimming all variables.

  5. #5
    chromachem is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    49
    I tried dimming the default printer as a string. It did not help.

    If you comment out the line DoCmd.RunCommand acCmdPrint then Set Application.Printer = strDefaultPrinter the code switches the printer back to the default as needed.
    As soon as you remove the comment form the line of code and run DoCmd.RunCommand acCmdPrint, the printer does not switch back to the default printer.


    Code:
       strDefaultPrinter = Application.Printer.DeviceName
       Set strDefaultPrinter = Application.Printer
       Set Application.Printer = Application.Printers("Brother QL-570 LE")
       DoCmd.OpenReport "rptLabels", acViewPreview
       DoCmd.RunCommand acCmdPrint
       DoCmd.Close acReport, "rptLabels"
       Set Application.Printer = strDefaultPrinter
    If you google reset default printer Access VBA on line you can find lots of people that have run into this same problem. This is the only solution found anywhere:

    Microsoft has a printer dialog that does not change the default windows printer, but allows the users to select printer and printing options, see http://support.microsoft.com/kb/322710/EN-US/#7 for download and sample code. Unfortunately this fix doesn't seem to install in Win 10 64 bit.

    So... It seems to be a common problem with no solution for my OS. Quite the challenge. If anyone can come up with a fix, it would be greatly appreciated.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  7. #7
    chromachem is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    49
    I ended up using the SetDefaultPrinter API. I went back and looked on line and essentially used the code below.
    Code:
    Option Compare Database
    Option Explicit
    
    Public Declare Function SetDefaultPrinter Lib "winspool.drv" _
    Alias "SetDefaultPrinterA" (ByVal pszPrinter As String) As Long
    
    Public myPrinter As String
    
    Private Sub Form_Load()
    myPrinter = Application.Printer.DeviceName 'grab default printer so we can reset it on exit
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    SetDefaultPrinter myPrinter 'reset to default
    End Sub
    


    THIS WORKS!!!!!!!!!!!!!!!!!!!! Thanks to all for looking.

    Last stupid question (of the day). How do I mark a thread solved on this forum?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Set Default Printer
    By jo15765 in forum Modules
    Replies: 5
    Last Post: 02-18-2016, 07:05 AM
  2. Using a thremal printer for labels
    By kcmiuser in forum Reports
    Replies: 3
    Last Post: 03-24-2014, 01:49 PM
  3. Replies: 3
    Last Post: 02-25-2014, 11:46 AM
  4. Print to Default Printer
    By bsc0617 in forum Access
    Replies: 7
    Last Post: 10-10-2013, 07:46 AM
  5. Trying to Change Default printer
    By sims.anderson2010 in forum Programming
    Replies: 2
    Last Post: 03-08-2012, 08:07 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