Specifying printers in code?

connexion

Registered User.
Local time
Today, 20:29
Joined
Jul 30, 2003
Messages
72
Hi there,

Anyone got any good ideas for how to aim a print job at a specific printer when automating printing from within access.

I want to re-direct jobs to specific printers according to what code is being run at the time, resetting back to the default printer at the end of each routine if required.


I have read around this but didn't think it would be much harder then specifying a printer from the named printers on the local machine, regardless of the printer being local or networked, but like most things, it isn't apparently that easy!...or is it?

Thanks
Vince
 
Try this

Hello Vince

Well i'm not sure if i understood your question, but if what you want is to choose an available installed printer and send any report. Is not complicated at all
Code:
Private sub ThisPrn()

  Dim prn as printer
  Dim sRpt as string

  sRpt = "rptName"
   
  docmd.openReport srpt   

'check if there are more printers
     
       If isnull(PrinterList) then '*
           Reports!sRpt.UseDefaultPrinter = True
       Else
          For each prn in application.printers
                if prn.DeviceName = PrinterList then
                       set report.sRpt.printer = prn
                        Exit for
                 end if
           Next prn
      End if

docmd.openReport srpt   

End sub

*I assumed printerlist as the listbox with all printers names


Good luck

Estuardo
 
Last edited:
Re: Try this

Estuardo said:
*I assumed printerlist as the listbox with all printers names
Is there a way to automatically create a listbox with all the printers names installed on a users computer?
 
The following code lists all the printers on my NT4 machine:
Code:
Public Sub devListPrinters()
'lists the current printers to the debug window
Dim I As Integer
Dim S As String
Dim R As Long
Dim Buffer As String

' Get the list of available printers from WIN.INI
Buffer = Space(8192)
R = GetProfileString("PrinterPorts", vbNullString, "", Buffer, Len(Buffer))

' Display the list of printers
Do
    I = InStr(Buffer, Chr(0))
    If I > 0 Then
        S = Left(Buffer, I - 1)
        If Len(Trim(S)) Then Debug.Print S
        Buffer = Mid(Buffer, I + 1)
    Else
        If Len(Trim(Buffer)) Then Debug.Print Buffer
        Buffer = ""
    End If
Loop While I > 0
End Sub
Don't know how flexible this is, the newer OS's might be clever and realize they don't use win.ini and use the registry instead.
 
Does anyone know if the code from post 2 can be used in Access 2000 as I am getting the error:- User Defined Type not Defined

Thanks

Anthony
 
Taff said:
Does anyone know if the code from post 2 can be used in Access 2000 as I am getting the error:- User Defined Type not Defined
where is this occuring??
 
Hi Cable,

It is on line:-

Dim prn as printer


Ant.
 
ah Printers isn't an object/collection thats supported in any Access afaik, it is in VB though.
 

Users who are viewing this thread

Back
Top Bottom