Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
81
Добавлен:
11.05.2015
Размер:
2.11 Mб
Скачать

Print the Report

Now that the data source for the report has been set to the DAO Recordset, you can print, preview, or export the report normally. For instance, the following code prints the report to the default printer:

report.PrintOut

Once the data source has been set in the report object, runtime reporting can proceed normally. All features of the Crystal Report Engine are available to you. For more information, refer to the sections of this manual appropriate to the Report Engine development tool you are using.

Creating Data Definition Files

A data definition file is a tab-separated text file that contains information about field names, field types, and sample field data. Field names used in the data definition file must match the field names that will appear in the ActiveX data source that is specified at runtime. Field type information indicates the type of data in each field (string, numeric, date, etc.) and, if it is a string field, the maximum length of the string. Finally, sample field data is simply sample data that Seagate Crystal Reports can display in the preview window while you design the report.

For complete information on creating data definition files, see Creating Data Definition Files, Page 123. Seagate Crystal Reports installs a sample data definition file in the \Program Files\Seagate Software\Crystal Reports directory on your system. This file is named ORDERS.TTX and can be used with the Orders table in the XTREME.MDB sample database or the Xtreme sample data ODBC data source that was created when you installed Seagate Crystal Reports.

The following is an example of how fields are defined in a data definition file:

 

Order ID

Long

1

 

Customer Name

String 50

Sample string value

 

Order Date

Date

Jan 5, 2000

 

Order Amount

Currency

$1.00

The Active Data Driver supports the following data types in a data definition file:

 

 

 

 

 

Data Type

Description

 

 

 

 

 

 

 

 

BLOB

Fields that contain bitmap images.

 

Boolean

True/False Boolean value.

 

 

 

 

Byte

8-bit integer value.

 

 

 

 

Currency

64-bit floating-point value that can include a currency or percent sign.

 

 

 

 

Visual Basic Solutions

123

Data Type

Description

 

 

 

 

Date

Any date/time value. Examples include:

 

Jan 5, 1999

 

07/11/97 5:06:07

 

07/11/97

 

23:30:01

 

 

Long, int32

32-bit integer value.

Memo

Any string value over 254 characters long. You must indicate the maximum

 

number of characters for the string.

 

 

Number

64-bit floating-point value.

 

 

Short, int16

16-bit integer value.

 

 

String

Any string value under 254 characters long, such as a name, description, or

 

identification number that is not meant to be interpreted numerically. You must

 

indicate the maximum number of characters for the string.

 

 

NOTE: The data type BLOB is supported when connecting to RDO, ADO, DAO and the data control at runtime but not when connecting to CDO.

Although data definition files can be created manually using a text editor such as Notepad, Seagate Crystal Reports provides tools for simplifying the process. Each tool has its advantages. Review the process for using each tool described below to determine which best suits your own environment and development process.

Database Definition Tool, Page 124

Active Data Driver Functions, Page 125

Database Definition Tool

The Database Definition Tool is available from the Select Data Source dialog box when you begin designing a report based on the Active Data Driver. This tool allows you to design a data definition file as the first step of designing your report. From the Data Tab of the Create Report Expert:

1Scroll down and click the Active Data button. The Select Data Source dialog box appears.

2Click the Data Definition option in the dialog box to create a report based on a data definition file.

3Click New to create a new data definition file. The Database Definition Tool appears.

4Use the Database Definition Tool to create fields for your data definition file. Use the controls to enter field names, field types, and sample data that will appear in the Seagate Crystal Reports Preview Tab. If you select String as the field type, you will also be asked to specify a maximum string length.

5Click Add to add each new field to your data definition file. Each field appears in the list box at the bottom of the Database Definition Tool.

6Continue adding as many fields as necessary for your data definition file by entering the information in the controls of the Database Definition Tool, and clicking Add each time.

7You can delete a field that you have created by selecting the field in the list box and clicking Delete.

Visual Basic Solutions

124

8Click the Close button in the upper right of the Database Definition Tool dialog box when you are finished designing your data definition file. A message appears asking if you want to save the data definition file.

9Click Yes, and a Save File As dialog box appears.

10Save the data definition file where it can be accessed by your report file. When finished, the new data definition file will appear in the Data Definition text box in the Select Data Source dialog box.

11Continue creating your report.

Active Data Driver Functions

The Active Data Driver (P2SMON.DLL) is a standard dynamic link library that is normally used by Seagate Crystal Reports (or the Crystal Report Engine) to access ActiveX data sources such as DAO and ADO. The DLL is installed, by default, in your \WINDOWS\SYSTEM directory. In addition, the Active Data Driver exports functions that can be used at runtime from within your application to dynamically design a data definition file based on your data source, and a report file based on the data definition file. These functions are available to any development environment that supports DLL function calls.

NOTE: To use the functions in the Active Data Driver DLL, you must declare the functions first. Refer to your Visual Basic documentation for information on declaring DLL functions. Search for Crystal Active Data Driver Reference in Developer’s online Help for information about declaring the Active Data Driver functions.

To use the Active Data Driver Functions from Visual Basic:

1Obtain a valid Recordset object from your DAO, ADO, or Data Control data source, or a valid Rowset object using CDO.

2Call the function CreateReportOnRuntimeDS to create a data definition file based on your Recordset or Rowset object. For example:

CreateReportOnRuntimeDS(daoRs, “c:\reports\orders.rpt”, “c:\reports\orders.ttx”, True, False)

This example creates a data definition file named ORDERS.TTX, then creates a simple report file based on this data definition file and names it ORDERS.RPT. If the last argument is set to True, Seagate Crystal Reports, if installed on the system, will open automatically on the user’s machine, allowing them to make changes to the report file.

Notice that the first argument is a DAO Recordset object. If you are using this function in a language such as C or C++, you would pass a pointer to an IUnknown derived interface to the Recordset.

NOTE: For complete information on the functions provided by the Active Data Driver, search for Crystal Active Data Driver Reference in Developer’s online Help.

Visual Basic Solutions

125

Using ActiveX Data Sources at Design Time

The Active Data Driver is intended to allow reports to be based on ActiveX data sources such as ADO and DAO. Data definition files allow you to avoid specifying an actual data source until runtime. However, you may often need to simply specify an ADO data source at design time for the report.

The Select Data Source dialog opens when you click the Active Data button on the Data Tab of the Report Expert. This dialog box provides four options for selecting a data source to use in your report: specify an ODBC data source for ADO or RDO, specify an ADO connection string for OLE DB, specify a DAO recordset, or specify a data definition file. The Data Definition option has been thoroughly discussed earlier in this section. The remainder of this section will discuss selecting an ADO, RDO, or DAO data source.

The following topics are discussed in this section.

ODBC with ADO and RDO, Page 126

ADO and OLE DB, Page 127

DAO, Page 127

ODBC with ADO and RDO

1Click the ODBC option in the Select Data Source dialog box. This option allows you to connect to an ODBC data source through ADO or RDO. The currently selected data objects technology appears in parentheses next to the ODBC option.

Use the drop-down list box to select an ODBC data source that is available on your system.

Click the New button to create a new ODBC data source. Refer to Microsoft ODBC documentation for information on creating ODBC data sources.

Click the Advanced button to select ADO or RDO as the data objects technology used. This should match the technology used in your Visual Basic application.

2After you select your data source and data objects technology, you can click Next in the Select Data Source dialog box. The Select Recordset dialog box appears.

3If the ODBC data source requires log on information, specify a user name and password to log on.

4Determine if you want to create a Recordset or Resultset using an object available from your data source, such as a database table, or if you prefer to specify a SQL statement. Select the appropriate option in the Recordset section of the Select Recordset dialog box.

NOTE: For simplicity, RDO Resultsets are also referred to as Recordsets in this dialog box.

5If you want to connect to a database object, use the Object Type drop-down list box to select the type of database object, such as a Table, then select the object itself from the Object drop-down list box.

6If you want to obtain a Recordset using a SQL statement, write the SQL statement in the text box provided, or click Build to use the Microsoft Query application and Query Wizard to visually design your SQL statement.

Visual Basic Solutions

126

7Click Finish in the Select Recordset dialog box. Either ado or rdo will appear in the list box on the Data Tab of the Report Expert.

8Continue creating your report normally. While creating your report, the ado or rdo specification will act like a database table, providing all fields that have been obtained from your ADO Recordset or RDO Resultset.

ADO and OLE DB

1Click the ADO and OLE DB option in the Select Data Source dialog box. This option is designed to allow you to specify an ADO connection string that can connect to any OLE DB provider.

2Type the ADO connection string into the text box provided. You must be familiar with ADO to create a proper connection string. The following are examples of an acceptable connection string for ADO:

3DSN=Xtreme sample data;

4DATABASE=pubs;DSN=Publishers;UID=sa;Password=;

5Type in the first example shown here to follow along in this tutorial. Click Next in the Select Data Source dialog box when finished. The Select Recordset dialog box appears.

6Determine if you want to create a Recordset using an object available from your data source, such as a database table, or if you prefer to specify a SQL statement. Select the appropriate option in the Recordset section of the Select Recordset dialog box.

7If you want to connect to a database object, use the Object Type drop-down list box to select the type of database object, such as a Table, then select the object itself from the Object drop-down list box.

8If you want to obtain a Recordset using a SQL statement, write the SQL statement in the text box provided, or click Build to use the Microsoft Query application and Query Wizard to visually design your SQL statement.

9Click Finish in the Select Recordset dialog box. You will see ado in the list box on the Data Tab of the Report Expert.

10Continue creating your report normally. While creating your report, the ado specification will act like a database table, providing all fields that have been obtained from your ADO Recordset.

DAO

1Click the DAO option in the Select Data Source dialog box. This option allows you to connect to a database file through Data Access Objects (DAO).

2Select a database type from the Database drop-down list box. This list displays all DAO compatible database drivers installed on your system. Seagate Crystal Reports installs many DAO drivers for you. For this example, you can select Access as the database type.

3Use the Browse button to open the Select Database File dialog box. Use this dialog box to locate and select a database file. Seagate Crystal Reports includes several sample databases in the \Program Files\Seagate Software\Crystal Reports directory by default. You can select the XTREME.MDB Access file from this directory for this example.

Visual Basic Solutions

127

Соседние файлы в папке crystal