Embeddable Crystal Reports Designer Component

book list add book to my bookshelf create a bookmark purchase this book online

mastering crystal reports 9
Chapter 19 - Building Windows Applications with the Report Designer Component
Mastering Crystal Reports 9
by Cate McCoy and Gord Maric
Sybex 2003

So far we have shown how to view and manipulate a report. The RDC includes a Report Designer Component that allows you to provide Crystal Report design capabilities in your application. Figure 19.20 shows a Visual Basic application using the Report Designer. Notice how you can provide the user the same capabilities as Crystal Reports has in a custom application.

The Report Designer Component is an ActiveX control that you must add to the VB toolbox before it can be used. To add the component, select Project > Components and choose Embedded Crystal Reports 9 Designer Control.

In our application we will give the user the ability to open an existing report, create a new report, and modify designer options using the buttons we added to the top of our form, shown in Figure 19.19.

click to expand
Figure 19.19. Report Designer Component

To work with the Report Designer, you must make a reference to the Crystal Reports ActiveX Designer Design and Runtime Library. Select Project > References and choose Crystal Reports 9 ActiveX Designer Design and Runtime Library. In the following code example, notice that when we dimensioned the Application object and the Report object, we prefixed the object with CRXDDRT, as opposed to CRXDRT. We have been using the Crystal Reports 9 ActiveX Designer Runtime Library, CRXDRT, until now. Crystal Reports 9 ActiveX Designer Design and Runtime Library allows you to create and modify reports at runtime.

Dim crApp As New CRAXDDRT.Application Dim crRep As CRAXDDRT.Report

To open a report we use the OpenReport method of the Application object and set the Report variable to the newly open report. In this example we hard-code a report name to keep it simple; we could have also used a Common dialog box like we did in the previous example. Once a report is created, to display the report in the Report Designer you must assign the Report object property to the object variable that is referencing the Crystal report.

Private Sub cmdOpenReport_Click() Set crRep = _   crApp.OpenReport(App.Path & "/" & _ "design.rpt") CRDesignerCtrl1.ReportObject = crRep End Sub

You can also give your users the ability create a new report by using the NewReport method of the Application object and setting the Report variable to the new report:

Private Sub cmdNewReport_Click()     Set crRep = Nothing     Set crRep = crApp.NewReport     CRDesignerCtrl1.ReportObject = crRep  End Sub
Warning 

This code will run only if you have the Advanced Developer Edition of Crystal Reports. The Regular Developer Edition does not allow report creation. If you run this code without the correct license, you will get a “Creation feature not enabled” error.

To provide report preview capabilities you need to add the Crystal Report Viewer to your application. From the Project menu choose Components and select Crystal Report Viewer 9. We added the Report Viewer on top of the Report Designer and set the Visible property of the viewer to False so it can’t be seen. When the user clicks the Preview button, shown in Figure 19.20, we show the Report Viewer and assign to the viewer’s ReportSource property the object variable referencing the report.

Private Sub Form_Load()     CRViewer91.Visible = False End Sub  Private Sub cmdPreview_Click()     CRViewer91.Visible = True     CRViewer91.ReportSource = crRep     CRViewer91.Refresh     CRViewer91.ViewReport End Sub

When the user wants to go back to Report Design mode, we simply hide the Report Viewer again.

Private Sub cmdDesign_Click()     CRViewer91.Visible = False End Sub

click to expand
Figure 19.20. Previewing a report from the Report Designer

Reports created in the Report Designer can be saved to Crystal Report files, as shown here:

Private Sub cmdSaveReport_Click()     CRDesignerCtrl1.SaveReport ("c:/test.rpt")      End Sub

You can provide your users the same options that are in Crystal Reports to modify the Report Designer. In this case we are toggling the grid in the Report Designer:

Private Sub cmdDisplayGrid_Click()     If CRDesignerCtrl1.DisplayGrid = True Then         CRDesignerCtrl1.DisplayGrid = False     Else         CRDesignerCtrl1.DisplayGrid = True     End If End Sub
Note 

Refer to the Developers help file for “Embeddable Crystal Reports Designer Control Object Model” for the complete set of methods and properties for the Report Designer.

Use of content on this site is expressly subject to the restrictions set forth in the Membership Agreement
 
Conello © 2000-2003     Feedback


Mastering Crystal Reports 9
Mastering Crystal Reports 9
ISBN: 0782141730
EAN: 2147483647
Year: 2005
Pages: 217

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