Click to See Complete Forum and Search --> : printer selection using crviewer


epswing
August 20th, 2004, 01:12 PM
Regarding the CRViewer9 component in VB6, is
there any way to ask the user which printer
they wish to use?

http://greybox.ath.cx/pub/pics/linked/print.jpg

I get the report loaded up just fine, but
upon clicking the print button the windows
default printer is automatically selected.

Any suggestions?

malleyo
August 20th, 2004, 01:24 PM
Crystal Reports doesn't provide you with the option of choosing a printer. I ended up creating a separate form that asks the user for all the printer info and then it passes it to Crystal, bypassing Crystal's Print screen.


Dim prt As Printer

'This code would probably go in the Form_Load of your printer selection form

'Load Printers
For Each prt In Printers
cboSelectPrinter.AddItem prt.DeviceName
Next


'This code would go in the function that gets called
' when you click Print or OK in the Printer selection form

For Each prt In Printers

If prt.DeviceName = cboSelectPrinter.Text Then

Set Printer = prt

strDeviceName = prt.DeviceName
strDriverName = prt.DriverName
strPort = prt.Port

lngFromPage = Val(txtPageFrom.Text)
lngToPage = Val(txtPageTo.Text)
lngCopies = Val(txtCopies.Text)

Exit For

End If
Next

Set prt = Nothing


'This code goes after you set up your report

Report.SelectPrinter strDriverName, strDeviceName, strPort
Report.PrintOut False, intCopies, , intFromPage, intToPage

harmonycitra
August 20th, 2004, 01:32 PM
I think Report object will do the work (in Crystal 9)

Dim Appl As New CRAXDRT.Application
Dim Report As New CRAXDRT.Report

Set Report = Appl.OpenReport("Path")

Report.PrinterName = printername 'This will assign the printer name

Hope this will work

epswing
August 20th, 2004, 02:07 PM
Report.PrinterName = printername
"Compile Error: Can't assign read-only property"

This occurs when printername is Dim'd as a String or a Printer.

I'm giving malleyo's advice a go...

harmonycitra
August 20th, 2004, 06:19 PM
Sorry for that.

I should have checked before posting.

epswing
August 23rd, 2004, 09:42 AM
malleyo, question about your posted code...

you have...

lngFromPage = Val(txtPageFrom.Text)
lngToPage = Val(txtPageTo.Text)
lngCopies = Val(txtCopies.Text)

...and then...

Report.PrintOut False, intCopies, , intFromPage, intToPage


Where did intCopies, intFromPage and intToPage come from? When debugging mid-execution, VB tells me that those three variables are Empty. If I change those three to lngCopies, lngFromPage and lngToPage it gives me a type mismatch on the Report.PrintOut line.

Any Ideas?



Edit: Oh wow, VB6 crashed, found this error log:

Line 19: Class CRVIEWER9LibCtl.CRViewer9 of control CRViewer1 was not a loaded control class.
Line 25: The property name lastProp in CRViewer1 is invalid.
Line 26: The property name _cx in CRViewer1 is invalid.
Line 27: The property name _cy in CRViewer1 is invalid.
Line 28: The property name DisplayGroupTree in CRViewer1 is invalid.
Line 29: The property name DisplayToolbar in CRViewer1 is invalid.
Line 30: The property name EnableGroupTree in CRViewer1 is invalid.
Line 31: The property name EnableNavigationControls in CRViewer1 is invalid.
Line 32: The property name EnableStopButton in CRViewer1 is invalid.
Line 33: The property name EnablePrintButton in CRViewer1 is invalid.
Line 34: The property name EnableZoomControl in CRViewer1 is invalid.
Line 35: The property name EnableCloseButton in CRViewer1 is invalid.
Line 36: The property name EnableProgressControl in CRViewer1 is invalid.
Line 37: The property name EnableSearchControl in CRViewer1 is invalid.
Line 38: The property name EnableRefreshButton in CRViewer1 is invalid.
Line 39: The property name EnableDrillDown in CRViewer1 is invalid.
Line 40: The property name EnableAnimationControl in CRViewer1 is invalid.
Line 41: The property name EnableSelectExpertButton in CRViewer1 is invalid.
Line 42: The property name EnableToolbar in CRViewer1 is invalid.
Line 43: The property name DisplayBorder in CRViewer1 is invalid.
Line 44: The property name DisplayTabs in CRViewer1 is invalid.
Line 45: The property name DisplayBackgroundEdge in CRViewer1 is invalid.
Line 46: The property name SelectionFormula in CRViewer1 is invalid.
Line 47: The property name EnablePopupMenu in CRViewer1 is invalid.
Line 48: The property name EnableExportButton in CRViewer1 is invalid.
Line 49: The property name EnableSearchExpertButton in CRViewer1 is invalid.
Line 50: The property name EnableHelpButton in CRViewer1 is invalid.
Line 51: The property name LaunchHTTPHyperlinksInNewBrowser in CRViewer1 is invalid.
Line 81: Property Picture in imgMPAQ had an invalid file reference.

malleyo
August 23rd, 2004, 10:04 AM
Oops...

My code was set up using a User-defined Type for the FromPage, ToPage, and Copies, when I copied the code to the forum, I just changed them into normal variables. I didn't realize that PrintOut requires an Integer and not a Long. Sorry about that.

Should be:
intFromPage = CInt(txtPageFrom.Text)
intToPage = CInt(txtPageTo.Text)
intCopies = CInt(txtCopies.Text)

Report.PrintOut False, intCopies, , intFromPage, intToPage


In regards to the VB6 crash, did you make sure that CRViewer was checked in your Components list?

epswing
August 23rd, 2004, 10:05 AM
Edit: Oops, you posted while I was typing. I'll give that a try, thanks.

Edit2: If CRViewer wasn't checked as a component, wouldn't I not be able to add the control to the form?

epswing
August 23rd, 2004, 10:14 AM
Finally got everything working really well. Thanks a lot malleyo and harmonycitra for giving me a hand.

Here's what worked:

Private Sub CRViewer1_PrintButtonClicked(UseDefault As Boolean)

Dim cOrientation As CRPaperOrientation
Dim cSize As CRPaperSize
cOrientation = report.PaperOrientation
cSize = report.PaperSize

Dim p As Printer
For Each p In Printers
If p.DeviceName = cmbPrinters.Text Then
report.SelectPrinter p.DriverName, p.DeviceName, p.Port
Exit For
End If
Next p

report.PaperOrientation = cOrientation
report.PaperSize = cSize

Call SetLastUsedPrinter

End Sub

dilemma
August 24th, 2004, 11:35 PM
Guys what if you use Printersetup command before you print it with print button or with printout command :

try this :

http://www.xsorbit3.com/users/softwaredilemma/index.cgi?board=CrystalReportGeneral&action=display&num=1093379441&start=0

Dean_Reedy
August 30th, 2004, 02:10 PM
As stated above try:

CRReport.PrinterSetup 0

This forces the Printer Selection box to appear. This can be placed before the the Report.Printout and in the CRViewer place it in the Printer_Button click event.


Dean

malleyo
August 31st, 2004, 09:43 AM
:eek:

As stated above try:

CRReport.PrinterSetup 0

This forces the Printer Selection box to appear. This can be placed before the the Report.Printout and in the CRViewer place it in the Printer_Button click event.


Dean
I spent several hours of my precious worktime looking for a solution such as this! I ended up having to code a form that would allow the user to choose a printer. And here it was so simple! Two lines of code! THANK YOU Dean!! :D