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.
viji_cAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rasenieroCommented:
in vb 6. we use common dialog! no idea
0
VBtomCommented:
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

       
0
viji_cAuthor Commented:
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.
0
VBtomCommented:
Hi viji_c

The sentence "Set printer = " may indeed change the default printer (though it's my experience that it usually doesn't).

I'm not familiar with crystal reports, but I believe at leas one of these two possible workarounds will work:
1)Declare a global variable
Public OldPrinter as printer

Then, before you change the printer:
Set Oldprinter = printer
Then call SelectPrinterByName to change the default printer.
Then print.
Then restore the old printer:
Set Printer = OldPrinter.

2)Adapt the sub a little and make it a function that return a printer-object:
Public Function SelectPrinterByName(Devicename as string) As printer
Dim i as integer, found as boolean
For i = 0 to printers.count-1
  If printers(i).devicename = devicename then
      found = true
      Set  SelectPrinterByName = printers(i)
      exit for
  end if
next i
Else
  msgbox "No printer called " & devicename & "found!", vbcritical
End if
End Sub

then:
Dim ptr as printer
set ptr = SelectPrinterByName("MY PRINTER")
CAXDRT.Report.ReportSource = myReport
CRAXDRT.Report.SelectPrinter ptr.Drivername, ptr.devicename, ptr.Port
Set ptr = nothing




0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CleanupPingCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.