Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to Select Printer for Data Report Designer

Status
Not open for further replies.

lrott

Programmer
Dec 7, 2002
6
US
I need to always use a specific printer to print a report, so I do not need to offer the choice of printers before printing. Here is my attempt:

Private Sub Form_Load()
Dim pr As Printer
For Each pr In Printers
Debug.Print pr.DeviceName
Combo1.AddItem pr.DeviceName
Next pr
Combo1.Text = Printer.DeviceName

Set pr = Printers(0) 'doesn't work
rptUnpaid.PrintReport False
Me.Hide
End Sub

Default printer is # 1 and is needed otherwise.

Any suggestions?
Thanks,
Leo
 
The Printer object and the printer.name property are not the same. This has been covered several times and a quick search for printers will bring up several threads, including:
thread222-915800

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
johnwm, Thanks for the response. After much more searching and reading, I have made these modifications, but it still prints to the system default printer.[sad]
Code:
SQLQuery = "SELECT Printer FROM UnpaidSummary "
rsUnpaidSummary.Open SQLQuery, dbTransact
If Not rsUnpaidSummary.EOF Then
 vntTemp = rsUnpaidSummary!Printer
 If IsNull(vntTemp) Then vntTemp = ""
  txtPrinter = vntTemp
 End If
rsUnpaidSummary.Close
ChangePrinter (txtPrinter)  'changes to correct printer

vntTempPrt = Printer.DeviceName   'correct printer here
rptUnpaid.PrintReport        
vntTempPrt = Printer.DeviceName   ' printer still here
RestorePrinter               ' default system printer
Here is my ChangePrinter Sub...
Code:
Public Sub ChangePrinter(txtprt As String)
Dim p As Printer
For Each p In Printers
If p.DeviceName = Printer.DeviceName Then
Set OldPrinter = p
End If
If p.DeviceName = txtprt Then
Set NewPrinter = p
End If
Next p
Set Printer = NewPrinter
End Sub
My understanding is that this is supposed to work only for this app, and revert after the app closes even if I did not do a restore.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top