|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Peter Norton's Guide to Visual Basic 6
Changing the Properties at RuntimeWhat you have just completed is the quickest way to execute a report from Crystal Reports. However, in most applications there is usually more than one report that the users will need to display or print, so you will need to change the Crystal Reports controls properties at runtime. Otherwise, you would need to place a separate report control for each report you supply to the user. All the major properties of the Crystal Reports control, such as ReportFileName and SelectionFormula, are available at runtime. The following sample code sets up the Crystal Reports control for a new report and specifies a selection criteria based on user input:
crReport.ReportFileName = "AddrList.rpt"
crReport.SelectionFormula = "{EntryList.State}=" & txtStateCd
crReport.action = crRunReport 'This is a constant for the value 1
The other property you might need to set at runtime is the DataFiles property. This property is not available at design time. It specifies the name of the database file that is used by the report. Unless the user installs your application in exactly the same directory that you have on your computer, you will need to tell the Crystal Reports control the location of the database file on the users PC. The DataFiles property is actually an array with the first element number of zero. If youre using more than one database in your report, you must set the value of each DataFiles array element for each database. For most of your reports, however, you will be using only a single database. The following line of code shows you how to set the value of the DataFiles property for the database. This line assumes that the database file is in the same folder as your application: crReport.DataFiles(0) = App.Path & "\AddressBook.mdb" Creating a Report Selection InterfaceIn most Visual Basic applications that have many reports associated with them, a good report-selection interface is required for the user to be able to select a report easily. In addition, the user should be able to modify the reports options and specify selection criteria. In an application that I developed, a Visual Basic form was used with several controls in conjunction with an input table to generate the report manager (see Figure 14.20).
This report manager displays report descriptions in a TreeView control with headings for each group of reports added to the list. It also uses the CommonDialog control to display the Printer dialog box. Using a TreeView control requires copious amounts of code to populate and control it. You could create a simpler version of this interface by replacing the TreeView control with a List Box control (see Figure 14.21).
These are only two of the many different managers that you could create using Visual Basic controls and the Crystal Reports Custom control. The only real limitation is your own imagination. SummaryIn this chapter, you learned how to use Crystal Reports to create professional-looking reports with very little effort. In addition, you added the Crystal Reports Custom control to a Visual Basic application and used it to run and then display a report in a window. What you have accomplished in this chapter has only scratched the surface of what the Crystal Reports product is capable of. However, you now have a solid foundation to build on when adding complex reporting to your application.
|
|
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. |