Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass number of copies to crystalreport activeX control?

Status
Not open for further replies.

MzKitty

Programmer
Oct 28, 2003
254
US
I'm using vs2008 with crystal 2008. I need to pass the number of copies to the crystalreport activex control so the user doesn't have to change the number of copies each time they print a ticket. The activex dialog box pops up, but I don't know how to preset the number of copies.

Thanks
Cathy
 
You can do this, but you need to bypass the print button in the Crystal Report Viewer. First, hide the print button by setting the Crystal Report Viewer's ShowPrintButton property to False. Then add a button to the form, and set it to be in front of the viewer. Put this in the button's Click event:

Code:
Dim pd1 As New PrintDialog

pd1.Document = New Printing.PrintDocument

pd1.Document.PrinterSettings.Copies = 12  'change this to the number of copies desired.

If pd1.ShowDialog = DialogResult.OK Then

    'cr1 is a crystal report object global to the form

    cr1.PrintOptions.PrinterName = pd1.PrinterSettings.PrinterName

    cr1.PrintToPrinter(pd1.PrinterSettings.Copies, pd1.PrinterSettings.Collate, pd1.PrinterSettings.FromPage, pd1.PrinterSettings.ToPage)

End If

This will show a print dialog, with the number of copies set to 12.

Note that if you want users to print only to the PC's default printer, you don't even need to show the dialog. Just use the PrintToPrinter method of the Crystal Report :


cr1.PrintToPrinter(2, True, 0, 0)

The first parameter is the number of copies. Put 0 for the last 2 parameters to print the entire document. The print dialog will not display.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks. I'll try it. I can't use the cr1.PrintToPrinter settting because it is a web application and the server does not have a printer installed. It has to use the client's default printer, so this wonderful setting doesn't work!

Cathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top