It is easy during development to inadvertently change the page setup setting of a report (or reports) to use a local printer. Once deployed your database will throw an error message nagging the user to switch from the one specified to his default printer. Why not avoid this issue altogether?!
I created a very simply procedure that simply go through the report collection and ensure that all the report are set to use the default printer. I then call this procedure (along with turn off SubDataSheets, deactivate AllowZeroLength property, etc.) in my deploy procedure I run before deploying any database to my users.
'---------------------------------------------------------------------------------------
' Procedure : RptPrntSetDef
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Ensure that all the report apge setups are set to use the Default Printer
' Copyright : The following may be altered and reused as you wish so long as the
' copyright notice is left unchanged (including Author, Website and
' Copyright). It may not be sold/resold or reposted on other sites (links
' back to this site are allowed).
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2011-05-23 Initial Release
'---------------------------------------------------------------------------------------
Sub RptPrntSetDef()
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim DbP As Object
Dim DbO As AccessObject
Set db = CurrentDb
DoCmd.SetWarnings False
Debug.Print "RptPrntSetDef Begin"
Debug.Print "================================================================================"
'Check Reports
Set DbP = application.CurrentProject
For Each DbO In DbP.AllReports
DoCmd.OpenReport DbO.Name, acDesign
If Reports(DbO.Name).Report.UseDefaultPrinter = False Then
Debug.Print "Editing Report '" & DbO.Name & "'"
Reports(DbO.Name).Report.UseDefaultPrinter = True
DoCmd.Close acReport, DbO.Name, acSaveYes
Else
DoCmd.Close acReport, DbO.Name, acSaveNo
End If
Next DbO
Debug.Print "================================================================================"
Debug.Print "RptPrntSetDef End"
Error_Handler_Exit:
On Error Resume Next
DoCmd.SetWarnings True
Set DbO = Nothing
Set DbP = Nothing
Set db = Nothing
Exit Sub
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: RptPrntSetDef" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub
<
Just what I was looking for!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
That setting is the bane of my existence !
Thank you for droping a kind comment Chris. It is always nice to know that other people have been able to benefit in some manner from my work/site.
Thank you very very much. I now run the code before I deploy any database. Great solution. 🙂
This helped! Was using Printer.DeviceName but that only showed me the default printer for the PC. The ‘.UseDefaultPrinter’ property was what I needed to be using to set to default.
Thanks!
Many thanks for the code. It saved me lots of time as I had 200 reports to go through. One thing I added was placing DoEvents just before the end of the For-Next loop so I could see the Immediate Window update in real-time.
Glad it helped!
This is what I am looking for but I am not sure where to put the code in VBA? Do I put it on the very first form on my Access file?
Create a new Standard Module and then insert the code. Then in the immediate window you can run it by entering
Call RptPrntSetDef
or you could run it through a form, macro, …
Worked like a champ, thank you for sharing this. Once the offenders were found and fixed, I discovered the same fix can be accomplished with a right click on the Print Preview, choose Page Setup, Page Tab, Radio button for Default vs. Specific Printer.
That’s great! Very helpful, thank you for sharing this, Daniel.
Hi Daniel,
I know this is a really old post however some of us still make a livelyhood using MS Access.
Can you share with us your deploy procedure? I currently have a Sub I run to prepare for release but I would like to review yours to see if there are things I should add to mine.
I searched for AllowZeroLength and SubDataSheets and the search brought me back to this page.
Thank you!