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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing to other printer from VB

Status
Not open for further replies.

Periko

Programmer
Feb 24, 2003
134
BE
Hi,

I want to specify another printer direct from VB, not via the printersetup method.
I want to use the selectprinter-method, sth I used before in the cr6 also and it is specified in the pdf you send me ! The only thing he isn't doing is
that he doesn't take the brother, but he still is taking the hp, which is actualy my default printer. Have I forgotten something ?
Thx in advance,
Pedro...



Private Sub Cmd_PrintHL_Click()
Dim hulp As String
Dim hulp2 As String
Dim test As Long
Dim p As Printer


Set Appn = CreateObject("CrystalRunTime.application")
Set cReport = Appn.OpenReport("c:\commdc\test.rpt")

hulp2 = "Testje van mijn eigen"
cReport.FormulaFields(1).Text = Chr(39) & hulp2 & Chr(39) ' "test =" & Chr(39) & hulp2 & Chr(39)

For Each p In Printers
MsgBox p.DeviceName & " " & p.DriverName & " " & p.port
DoEvents
Next

'cReport.SelectPrinter "\\BEETHOVEN\HP LaserJet 4000 PCL 5e", "winspool", "Ne00:"
cReport.SelectPrinter "\\NT-SERVER\Brother HL-1260", "winspool", "Ne01:"


If Chk_PrintSetup = 1 Then
cReport.PrinterSetup (test)
End If


cReport.PrintOut



Set cReport = Nothing

End Sub

 
to print to the default printer from within VB

cReport.PrintOut False, iCopies


To select another printer... (sPrinter)
If Printers.Count > 0 Then 'Doesn't work if no printers
For i = 0 To Printers.Count - 1
If Printers(i).DeviceName = sPrinter Then
cReport.SelectPrinter Printers(i).DriverName, _
Printers(i).DeviceName, Printers(i).Port
cReport.PrintOut False, iCopies
Exit For
End If
Next i
End If
Editor and Publisher of Crystal Clear
 
dear chelseatech,

Thankx for the useful tip ! It looks like mine but i had made a big mistake : in the selectprinter, the first argument is the drivername, the second the devicename. And I had specified it in the other direction. Reading your example learned me that I had switched the arguments !

Thank you very much !

Pedro...
 
However,

I have another problem now ! when i specify the other printer, the port won't work. He gives me an error on the port, due to the problem that my two printers are networkprinters. On the server, the brotherprinter is connected to LPT1 (local on the server) and the port he returned by printers(i).port = "Ne01:". When i do creport.printout (without false), he tells me that the port = LPT1, so he takes the port of the servermachine, and i get an error '-21........" error starting print job, please check your printer or networkconnection. When i pass thru the creport.printersetup(0), he shows me the chosen printer, i press ok and then he does print on that printer.
any idea ?

Thx in advance ...

Pedro...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top