Choosing Output Destinations


If your users will have a choice of output destinations (as the user does in the Xtreme Orders sample application), you need to create appropriate code to handle the user s choice. In the Xtreme Orders sample application, radio buttons and a text box allow the user to choose to view the report in the preview window, print the report to a printer, or attach the report as a .PDF file to an e-mail message. If the user chooses e-mail as the output destination, an e-mail address can be entered in a text box. Based on the user s selection, you need to set the output destination in your VB code.

If the user chooses to view the report on the screen, you need to activate the Report Viewer. In the sample application, this simply entails displaying the form that contains the Report Viewer control, by executing the form s Show method. The Form_Load event of this form will pass the Report object to the Report Viewer and execute the Report Viewer s ViewReport method.

As mentioned earlier, use of the Report Viewer is completely optional ”you are free to answer No when you are prompted about whether or not to add it when first adding the RDC to your project. However, if one of the output options will be to the screen (as in the Xtreme Orders sample application), make sure that the Report Viewer is eventually added to your project.

If you respond Yes to the RDC s Do you want to add the Report Viewer prompt, the RDC automatically adds the Report Viewer for you. It will create a new form, place the Report Viewer in the form, and automatically add rudimentary code to supply the Report object to the Report Viewer and resize the Report Viewer to be the same size as the form. If the RDC adds the Report Viewer automatically, you can leave this default behavior as is, move the Report Viewer object to another form, or build additional elements into the form that the RDC created automatically. You can also manually add the Report Viewer to your project later and supply code to pass the Report object to the Report Viewer.

If you wish to print the Report object to a printer, execute the Report object s PrintOut method. The syntax is as follows :

 object.PrintOut  Prompt  ,  Copies  ,  Collated  ,  StartPage  ,  StopPage  

In this statement, Prompt is a Boolean value indicating whether or not to prompt the user for printer options, Copies is a numeric value indicating how many copies of the report to print, Collated is a Boolean value indicating whether or not to collate the pages, and StartPage and StopPage are numeric values indicating which page numbers to start and stop printing on. The parameters are optional ”if you want to skip any in the middle, just add commas in the correct positions ”but don t include the parameter.

If you wish to export the report to a disk file or attach the report to an e-mail message as a file, use the Report object s Export method. The syntax is as follows:

 object.Export  PromptUser  

In this statement, PromptUser is a Boolean value indicating whether you want to prompt the user for export options. If you choose not to prompt the user for export options, you need to set properties of the report s ExportOptions object. The ExportOptions object contains many properties that determine the output destination (file or e-mail), file format (Word, Excel, PDF, XML, and so on), filename, e-mail address, and more. Many of these properties accept integer values or RDC-supplied descriptive constants. If you choose MAPI as the destination, the user s PC needs to have a MAPI-compliant e-mail client installed, such as Microsoft Outlook or Eudora Pro. Look for all the available ExportOptions properties by searching the online Help for ExportOptions object.

In the Xtreme Orders sample application, the following code is used to choose an output destination, as well as to specify a file type and e-mail information, based on user selection:

 'Set output destination 
If optPreview Then frmViewer.Show
If OptPrint Then Report.PrintOut (True)
If OptEmail Then
With Report
.ExportOptions.DestinationType = crEDTEMailMAPI
.ExportOptions.MailToList = txtAddress
.ExportOptions.MailSubject = "Here's the Xtreme Orders Report"
.ExportOptions.MailMessage = _
"Attached is a PDF file showing the latest Xtreme Orders Report."
.ExportOptions.FormatType = crEFTPortableDocFormat
.Export (False)
End With 'Report
End If 'optEmail
Caution  

If you use the Report object s Export method to export or send the report attached to an e-mail message, make sure you specify all the necessary ExportOptions object properties. If you fail to specify necessary properties or specify them incorrectly, an error may be thrown. Or, the user may be prompted to specify export options, even though you specifically add a false argument to the Export method. If the export takes place at an unattended machine, your application has to wait for a response, even though no user is available to respond.




Crystal Reports 10
Crystal Reports 10: The Complete Reference
ISBN: B005DI80VA
EAN: N/A
Year: 2004
Pages: 223
Authors: George Peck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net