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