Posted on 2003-04-01
Medium Priority
Last Modified: 2007-12-19
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.
Question by:viji_c
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8255474
in vb 6. we use common dialog! no idea

Expert Comment

ID: 8259368
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
   msgbox "No printer called " & devicename & "found!", vbcritical
End if
End Sub


Author Comment

ID: 8261680

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.

Accepted Solution

VBtom earned 200 total points
ID: 8268743
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
  msgbox "No printer called " & devicename & "found!", vbcritical
End if
End Sub

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


Expert Comment

ID: 9473888
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 
Post your closing recommendations!  No comment means you don't care.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question