Results 1 to 3 of 3
  1. #1
    sims.anderson2010 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    4

    Trying to Change Default printer


    I am trying to change the default printer for a list of reports. I want to change the printer then print the report and loop through a list of reports. It all works except for one minor issue. When I am done looping through the reports, and set the printer back to the original, it doesn't work. Throws no errors, but when I exit access and check under devices and settings, no printer is set as default. Next time I enter access and try to run the report, it says that the default printer is not set up correctly.

    Here is my code:
    Code:
    Private Sub CmdPrintUnitReports_Click()
    On Error GoTo Err_CmdPrintUnitReports_Click
    
        Dim dbs As Database
        Dim rst As Recordset
        Dim NewPrt As String
        Dim prt As Printer
        Dim str As String, str2 As String
        
        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset("select * from tbl_unit_printers")
       
        Set prt = Application.Printer
    
        While Not rst.EOF
            
            NewPrt = ""
            NewPrt = rst!Printer
            
            Set prt = Application.Printer
            Set Application.Printer = GetPrinter(NewPrt)
              
            str = "CURRENTUNIT like '*" & rst!Unit & "*'"
    
            'Print report to unit printer
            DoCmd.OpenReport "Rpt_WARDClassSchedule_ByUnit", acNormal, , , , str
    
            Set Application.Printer = prt
            rst.MoveNext
        Wend
    
        Set Application.Printer = prt
    
        
        'MsgBox "Reports printed to the units.", vbOKOnly
    
    Exit_CmdPrintUnitReports_Click:
        SetDefaultPrinter DefaultPrtStr
        Exit Sub
    
    Err_CmdPrintUnitReports_Click:
        MsgBox Err.Description
        Resume Exit_CmdPrintUnitReports_Click
        
    End Sub
    Any help would be appreciated

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Don't know if will help but don't see reason for the prt lines inside the loop. Can't see real problem with code. Have you step debugged?
    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.

  3. #3
    sims.anderson2010 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    4
    Sorry. I have now fixed the error. At the end of the Code, I had left this line.

    Code:
        'MsgBox "Reports printed to the units.", vbOKOnly
    
    Exit_CmdPrintUnitReports_Click:
        SetDefaultPrinter DefaultPrtStr
        Exit Sub
    
    Err_CmdPrintUnitReports_Click:
        MsgBox Err.Description
        Resume Exit_CmdPrintUnitReports_Click
        
    End Sub
    Apparently (I don't know the reason) Albert D.Kallal's Printer Setup Module does not work in Windows 7. It works for Access 2010 but not under Windows 7. When we changed to Windows 7 from Windows XP, this broke the DB. Another thing that Had to be changed was a reference to Compataui.dll which Windows XP uses for compatability (Database was created in Access 2003, Used later in 2010).

    Thanks for the suggestion. The reason for the extra set printers in the loops (at the beginning and the end) was just brainstorming during the troubleshoot process. Totally not needed. May actually cause slight lag as the database grows.

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

Similar Threads

  1. Select Default Printer
    By pkstormy in forum Code Repository
    Replies: 4
    Last Post: 03-10-2015, 09:26 AM
  2. How to change default view at launch?
    By seawulf in forum Access
    Replies: 3
    Last Post: 09-04-2011, 12:57 PM
  3. Programmatically change default switchboard at startup?
    By romeo_echo in forum Programming
    Replies: 4
    Last Post: 08-05-2011, 11:45 AM
  4. Replies: 7
    Last Post: 03-04-2011, 12:46 PM
  5. Forms to Printer
    By Roland in forum Reports
    Replies: 1
    Last Post: 11-22-2010, 10:16 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