View Full Version : Specifying printers in code?


connexion
08-07-2003, 08:33 AM
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

Estuardo
09-04-2003, 05:52 AM
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

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

Cosmos75
10-14-2003, 07:24 AM
Originally posted by Estuardo
*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?

cable
02-02-2004, 05:54 AM
The following code lists all the printers on my NT4 machine:
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.

Taff
06-10-2004, 07:40 AM
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

cable
06-11-2004, 07:17 AM
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??

Taff
06-11-2004, 07:28 AM
Hi Cable,

It is on line:-

Dim prn as printer


Ant.

cable
06-11-2004, 10:15 AM
ah Printers isn't an object/collection thats supported in any Access afaik, it is in VB though.