can i change the default printer for the report? (1 Viewer)

martinr

Registered User.
Local time
Today, 20:04
Joined
Nov 16, 2011
Messages
74
My workstation has a default printer that only prints A4, but I have an Access 2007
file with reports that require A3.
When I open these reports they see the A4 'default' printer.
If I try to change to the A3 printer in the report page setup (in design or print preview mode) it doesn't change - it keeps the default 'A4' and/or Access crashes.
If I change my workstation default printer to
the A3 printer and then open the Access file & report it works Ok (it picks up the A3 printer as default).
can I use VBA to set the default printer and page setup to A3 when the report opens?
 

JHB

Have been here a while
Local time
Today, 12:04
Joined
Jun 17, 2012
Messages
7,732
What happen if you click the "Print" icon, can't you choose the correct printer then?
If you open the report in design view and try to print it out (File->Print->Print), are you able to choose the correct printer, (if yes remember to save the report)?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:04
Joined
Sep 12, 2006
Messages
15,638
You ought to be able to change the default printer in design mode. I can't think why that would not work.

But anyway, to do it in code, you have to change the default printer for access to a different printer, then set it back to the original after you're done

basically iterate all the printers until you find the one you want

Code:
 function setprinter (requiredprinter as string) as boolean

Dim ptr As Printer
Dim useprinter As Printer
    
                
        'try and find this printer
        For Each ptr In Application.Printers
            If ptr.DeviceName = requiredprinter Then
                Set useprinter = ptr
                GoTo gotit
            End If
        Next

 noprinter:
        MsgBox ("The expected printer: " & requiredprinter & " was not found. The " & Report & " will be set to print to your default printer. ")
        setprinter = false
        Exit Function
            
gotit:
        On Error GoTo badPrinter
        Set Application.Printer = useprinter
        setprinter=true
         exit function
  
 badprinter
         'include some notification here
         setprinter=false
  
 end function
then restore the printer is easy

Code:
Function clearprinter() As Boolean
'reassign the printer to the default
    Set Application.Printer = Nothing
 End Function
 

Users who are viewing this thread

Top Bottom