Link to home
Start Free TrialLog in
Avatar of viji_c
viji_c

asked on

SelectPrinter

My requirement is to set the printer to the report during run time.
I noticed there is a SelectPrinter method that accepts the port name, printer name and the driver.
I only have the information about the printer naem at this time. How can I find the other info or is there another method in the report object that I can use. I am using VB.NET and Crystal Reports 9.0.

Thanks in advance.
Avatar of raseniero
raseniero

in vb 6. we use common dialog! no idea
Try calling this procedure with the printername as argument (I do it like this in VB6, don't know it it works in vb.net):

Public Sub SelectPrinterByName(Devicename as string)
Dim i as integer, found as boolean
For i = 0 to printers.count-1
   If printers(i).devicename = devicename then
       found = true
       Set Printer = printers(i)
       exit for
   end if
next i
If found then
   msgbox "Active printer is now:" & vbcrlf & _
          "Devicename: " & printer.devicename & vbcrlf & _
          "Port: " & printer.port & vbcrlf & _
          "Driver: " & printer.driver, vbinformation
Else
   msgbox "No printer called " & devicename & "found!", vbcritical
End if
End Sub

       
Avatar of viji_c

ASKER

VBtom,

Thanks. But this code would set the printer selected (by the user in my form) to the default printer and my report object automatically prints it to that printer and this does seem to solve the problem.
But I shouldn't change the default printer as other applications in the system should still print to the original default printer. I need to set the printer to the crystal report object so that other applications are unaffected. I found that there is a method SelectPrinter for the crystal report object. But it requires port name and device name.

CAXDRT.Report.ReportSource = myReport
CRAXDRT.Report.SelectPrinter(pDriverName as String, pPrinterName as string, pPortName as string)

when I set blank strings to the drivername and port name, the port name gets assigned somehow automatically during runtime(probably the system has identified the printer) but when I give Report.printout() it throws an exception that the printer network connection is not valid. check...

Is there a way I can get the driver name of the printer or Is there something I am missing.
ASKER CERTIFIED SOLUTION
Avatar of VBtom
VBtom

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
viji_c:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.