Adding the RDC to Your Project


The first step in using the RDC is to add it to your project. After installing Crystal Reports 10 Developer or Advanced Edition, the RDC should be properly registered on your system and ready for use. If you discover that Crystal Reports tools don t appear within the VB IDE, rerun Crystal Reports 10 setup from the Windows Control Panel and ensure that the Report Designer Component is selected.

click to expand

To begin using Crystal Reports with Visual Basic:

  1. Start Visual Basic and create a new project, or open the existing project with which you wish to use the RDC.

  2. Choose Project Components from the pull-down menus , or press CTRL-T. The Components dialog box will appear.

  3. Click the Designers tab. You ll see a list of ActiveX designers registered on your system. Ensure that the Crystal Reports 10 designer is selected and then click OK.

    click to expand
  4. Using the Project pull-down menu, choose the Add Crystal Reports 10 option (it may appear on the More ActiveX Designers submenu in VB 5). The RDC will be added to Visual Basic, and the Report Gallery dialog box will appear, as shown in Figure 27-1.

    click to expand
    Figure 27-1: The RDC inside Visual Basic

    Tip  

    Crystal Reports 10 attempts to add the RDC directly to the Project menu automatically when it s installed. If you need to add it manually with Project Components, it will stick from that point forward. You won t have to add it each time you want to use the RDC with a new VB project.

The RDC begins by displaying its own version of the Report Gallery. The RDC Report Gallery is very similar to the Report Gallery that appears when you create a new report in the Crystal Reports program, with a few changes. For example, there isn t an OLAP report option here, and the From an Existing Report option has been added. Your initial choices in the Report Gallery determine how your main report is designed inside the RDC.

Importing an Existing Report

If you ve created an .RPT file in Crystal Reports 10 or an earlier version and you want to use that report in the RDC, click the From an Existing Report radio button and click OK. A File Open dialog box will appear, in which you can choose the .RPT file that you wish to import. Once you ve chosen the report file, you are prompted to add the Report Viewer to your project.

Here, you can determine whether you want the Report Viewer added to a new form in your project and, if you do, decide whether you want the Report Viewer form to be set as the startup form. If you need to preview the report in a window from within your VB application, you need to add the Report Viewer. Although you can do it later if you need to, the RDC will offer to add it automatically, along with some simple code to tie the report to the viewer. If your report will be used strictly for exporting, e-mailing , or printing to a printer, you don t need to add the Report Viewer control because it won t be used.

If you import a report and add the Report Viewer to a new form, your screen will look something like the one shown in Figure 27-2.

click to expand
Figure 27-2: An imported report and the Report Viewer

You ll notice that the RDC design window looks quite similar to the regular Crystal Reports design window ”many of the features and report design steps apply equally to both environments. There are several ways of carrying out functions in the RDC design window: by using toolbox and toolbar buttons, by choosing items from the Field Explorer at the left of the report, and by right-clicking in the design window and choosing options from the pop-up menus. As with the regular Crystal Reports designer, you can select objects in the RDC design window and then move, resize, format, or delete them. Steps for these functions are basically the same as they are for regular Crystal Reports (with the exception that all RDC functions must be chosen with toolbar buttons and right-clicks ”there are no Crystal- related pull down menus here, as there are in regular Crystal Reports).

Remember that when you import an .RPT file into the RDC, the RDC simply copies the contents of the .RPT file into the design window and then completely disregards any changes that may later be made to the original .RPT file. Also, if you make any changes to the report inside the RDC, there will be no effect on the original .RPT file. You are not creating a real-time link to the .RPT file.

Tip  

If you want to save the contents of the RDC designer to an external .RPT file to use for other purposes, you may do so. Right-click in the design window and choose Report Save To Crystal Reports File from the pop-up menu.

While the RDC design window may not provide any particular functional advantage over the regular Crystal Reports designer (except that you don t have to exit VB to use it), the real benefit is the object model that it opens for report contents. When you select an individual Report object, such as a database field or text object, or a report section, such as the report header or details section, you ll see design-time properties in the Properties box. Also, by using the internal report designer, your report design is saved as a .DSR file along with .FRM, .BAS, and other files that make up your VB project. When you compile the project, the report design is embedded in the application s .EXE file ”there are no external .RPT files that your end users may inadvertently (or purposely) change.

As you can with properties for a combo box, radio button, form, or other regular VB control, you can set properties at design time for any of these report elements as well. The Properties box and pop-up menu options, such as the Format Editor, interact with each other. For example, you can select a date field, right-click it, and choose Format from the pop-up menu. On the Date tab of the Format Editor, you might choose a spelled-out month and four-digit year, showing no day at all. When you click OK to close the Format Editor and then look in the Properties box, you ll notice that the Day Type property has changed to 2 “ crNoDay, the Month Type property has changed to 3 “ crLongMonth, and the Year Type property has changed to 1 “ crLongYear. The opposite behavior is also true ”changes you make in the Properties box will be reflected elsewhere in the RDC dialog boxes.

Tip  

Depending on how you plan to integrate your report and how much customization you want to perform at run time, you may want to rename some of the default names given to objects by the RDC. When you begin looking through report objects in your VB code, recognizing what SubHeading represents is easier than recognizing what Text25 represents. If you are using stand- alone Crystal Reports, any name you give an object on the common tab of the Format Editor will remain when the report is imported into the RDC.

After you modify your report as necessary, save the report design the same way you save changes to a form, module, or project file from within VB. Just click the Save button on the toolbar, right-click the Designer object in the Project Explorer window, and choose Save from the pop-up menu, or just close the project or VB. You ll be prompted to choose a filename for the RDC designer, just as you would for a form or module. Choose a path and filename for the designer file ”the default file extension for ActiveX designers is .DSR. When you next open the VB project, the .DSR file will load with the rest of the project files, and all properties and characteristics of the report design window will reappear.

Creating a New Report

Although the ability to import an existing .RPT file into the RDC is an excellent way to integrate an existing .RPT file into a Visual Basic application, you may prefer to maximize the power of the RDC and design the report entirely inside the Visual Basic IDE from scratch. The RDC allows you to do this with one of the Report Gallery choices that appear when you first add the RDC to your project.

If you choose one of the report experts, you ll be led section by section through the expert dialog box, much as you are when you use the report wizards inside regular Crystal Reports (refer to Chapter 1 for more information). If you choose the Blank Report option, you are presented with an empty report design window in which you need to choose database connections, tables, and fields individually to add to the report. Start by right-clicking in the window and choosing Database Database Expert from the pop-up menu.

Choosing a Report Data Source

When you import an existing .RPT file into the RDC, the report inside your VB application will use the same data source as the imported report did (such as ODBC or a native database driver). These data sources are all provided by Crystal Reports functionality, separate from any database-connectivity features within Visual Basic.

However, when you create a new report from scratch using a report expert in the RDC, you have several choices for how your report will connect to a database. Because the RDC is so tightly integrated with Visual Basic, you may want to consider using a database connection that can easily be manipulated from within your VB code. In particular, the RDC can connect to data using various Microsoft data-access methods provided by Visual Basic. These include Data Access Objects (DAO), Remote Data Objects (RDO), and ActiveX Data Objects (ADO). In addition, you ll be able to connect directly to an existing data environment that you may have already defined in your VB application ( consult the VB documentation for more information on the Data Environment).

When you re ready to choose a data source, the Database Expert will appear, as shown in Figure 27-3.

click to expand
Figure 27-3: Database Expert

The Data Environment category, within the Project Data folder, will have entries in it only if you ve already added and defined a Visual Basic 6 Data Environment (which is another example of an ActiveX designer) in your project. When you expand this category, the set of connections and commands in the Data Environment will be available to be chosen for your report.

The remaining items in the Database Expert are identical to those displayed in the regular Crystal Reports designer, described in more detail in Chapter 16. Open the desired category, supply logon credentials (if required), and add one or more tables to the Selected Tables list. You can also create new Crystal Reports 10 SQL Commands in the Database Expert (also discussed in Chapter 16).

If you add more than one table, you must link the tables before proceeding to report design. Click the Links tab of the Database Expert (it will appear only if you add more than one table). Once you ve properly linked tables (discussed in detail in Chapter 16), click the Database Expert s OK button to proceed with report design.

Adding Objects

If you are using one of the report experts, you ll design the report by using the simple sectioned dialog box. Since this approach is virtually identical to the technique discussed in Chapter 1, you should refer to that chapter if you re unfamiliar with designing a report with an expert.

If you chose the Blank Report option (or if you ve already closed the report expert but want to add additional objects to the report), use the Field Explorer on the left side of the RDC design window to add objects to the report. For example, to add a field from the database, click the plus sign next to the database fields category to display the data source(s) the report is based on. Click the plus sign next to the data source to see the fields contained in it. Then, just drag and drop the fields you want to the desired section of the report design window.

click to expand

To create new formulas, parameter fields, running totals, or SQL expression fields, right- click their category in the Field Explorer and choose New from the pop-up menu. When the new object has been added, you can drag and drop it on the report. Special fields can also be added to the report by dragging and dropping them from their area of the Field Explorer.

After you add objects, you can select them and move or resize them just as you would in regular Crystal Reports. You can format an object that you ve selected by right-clicking and choosing the appropriate choice from the pop-up menu. And, don t forget that you also have Visual Basic properties for every object or report section in the report. Select the object or report section and make design-time property choices in the Properties box ”that s the power of the VB-integrated RDC.

Tip  

There are many capabilities and design techniques available that you can apply to the RDC, as you do with regular Crystal Reports. Look at the chapters in Part I of this book for ideas and techniques for designing sophisticated reports.




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