|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Peter Norton's Guide to Visual Basic 6
Using the Crystal Reports Custom ControlThe first step in accessing Crystal Reports is to make the control available to your program. If Visual Basic is not started, start it and then create a new project. Now you must add the Crystal Reports Custom control to your Visual Basic toolbox using the Components dialog box (see Figure 14.17). To open the Components dialog box choose Project, Components. In this dialog box, you can specify which custom controls are available in your project.
After the Crystal Reports control is available in your toolbox, you can use it in your program. To gain access to the control, simply select it from the toolbox and place it on the form where you will access the reports from. Because the Crystal Reports control is not visible at runtime, it appears only as an icon on your form. After the control is on the form, you can set the properties that access the reports you create with the report designer. Additionally, you should change the Name property to reflect your programs use of the control. For this example, set the Name property to crReport. Selecting the Report to RunThe key property you must specify is the ReportFileName property. This property specifies the actual report that you will run from your program. You can easily set this property using the Property Pages dialog box. Click the ellipsis button that appears to the right of the property in the Properties window as shown in Figure 14.18. From this page, you can specify the name of the report and the reports destination.
On the General tab of the Property Pages dialog box, either type the name of the report into the field for the ReportFileName property, or select the report from a file dialog box by clicking the ellipsis button on the Property Pages dialog box. Selecting the ReportFileName is the minimum requirement for Crystal Reports to run a report. The other tabs on the Properties page enable you to customize the report by specifying the following options for the report:
Modifying the Optional PropertiesAlthough the ReportFileName is the only required property for the report, you can choose to set several optional properties for the report. The first of these properties is the SelectionFormula property. This property enables you to limit the number of records that will be included in the report. The SelectionFormula property is similar to the Where clause of an SQL statement, but it uses its own particular format to enter the information. To specify the SelectionFormula, you must specify the name of the recordset and the field to be compared. You must express this recordset/field combination in dot notation and enclose it in curly brackets. After specifying the recordset and field, you must specify the comparison operator and the value to be compared. The final result is an expression like the following:
{MemberShipList.OrgCode}=1
You also can use multiple expressions by including the And or Or operators.
The CopiesToPrinter property enables the user to specify how many copies of the report are needed. This property can be set to any integer value. Activating the Custom ControlAfter you have added the Crystal Reports control to your form and set the properties, you are almost ready to start printing. The final step is to have the Visual Basic code tell Crystal Reports when it should print the report. This is done by adding a single line of code to initiate the report. The following line of code sets the Action property of the Crystal Reports control to 1, which is the value that starts the printing process: crReport.Action = crRunReport 'This is a constant with the value of 1
In the project, add a command button to the default form and place the previous line of code in its Click event routine. Now run the program and click the command button to run the report. The report you specified in the Properties page is then executed and displayed in its own window (see Figure 14.19).
Remember that this was just a simple example of displaying a report from a program. There are many more options, properties, and methods you can access that enable you to customize how the report looks when it is displayed.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |