Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SelectPrinter

Posted on 2003-04-01
6
Medium Priority
?
931 Views
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.
0
Comment
Question by:viji_c
5 Comments
 

Expert Comment

by:raseniero
ID: 8255474
in vb 6. we use common dialog! no idea
0
 
LVL 3

Expert Comment

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

       
0
 

Author Comment

by:viji_c
ID: 8261680
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
 
LVL 3

Accepted Solution

by:
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
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
 

Expert Comment

by:CleanupPing
ID: 9473888
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Make the most of your online learning experience.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Simple Linear Regression
Six Sigma Control Plans

580 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