Академический Документы
Профессиональный Документы
Культура Документы
Once you have selected a data source or data definition file and designed a report
based on that data source or file, you can begin programming your Visual Basic
application to obtain a recordset from an ActiveX data source, open the report
file, set the report file to use the recordset object from the ActiveX data source,
then print or export the report file. This process requires using the functionality
of the Crystal Active Data Driver in conjunction with the Report Designer Component
or one of the other Crystal Reports development tools. See the "Visual Basic
Solutions" chapter in the Crystal Reports Technical Reference Guide, or the Crystal
Reports Developer's Help (CrystalDevHelp.chm) for more information on the other
Crystal Reports development tools.
The following tutorials use the Report Designer Component Automation Server in
Visual Basic 6.0. This section assumes a familiarity with the Report Designer
Component Automation Server. If you need more information on how to use the
automation server, see the Report Designer Component Object Model.
To begin, you must obtain a Recordset object from a runtime ActiveX data source.
This data source can be opened through DAO, RDO, ADO, the Visual Basic Data
Control, Crystal Data Objects (CDO), or a class that implements the Crystal Data
Source Type Library. For information on DAO, RDO, and ADO, refer to Microsoft
documentation. For information on the Visual Basic Data Control, refer to your
Visual Basic documentation. For information on CDO, see Crystal Data Object . For
information on the Crystal Data Source Type Library, see Crystal Data Source Type
Library.
This tutorial creates a Recordset object from the Orders table of the XTREME.MDB
sample database using DAO. The Recordset concept is used by DAO, ADO, and the
Crystal Data Source Type Library. If you are using RDO, you will need to obtain a
rdoResultSet object. If you are using CDO, you will need to obtain a Rowset object
(see Crystal Data Object).
Note: You must add the Data Access Objects component to your Visual Basic
project before performing the following steps. For instructions on using DAO with
Visual Basic, refer to your Visual Basic documentation.
� Declare variables for the Database and Recordset objects in your Visual Basic
application. This can be handled in the declarations section of a form or module.
Use code similar to this:
Dim db As New DAO.Database
Dim rs As DAO.Recordset
� Obtain a Database object from the Xtreme database.
Set db = DBEngine.Workspaces(0).OpenDatabase( _
"c:\Program Files\Seagate Software\Crystal Reports\xtreme.mdb")
� Obtain a Recordset object from the Orders table of the Xtreme database.
Set rs = db.OpenRecordset("Orders", dbOpenTable)
� Obtain a Report object by opening the report file you created earlier. This
example uses the file ORDERS.RPT.
Set CRXReport = CRXApplication.OpenReport("c:\reports\Orders.rpt", 1)
Once you have a Database object for the Report object, you can pass the Active data
source to the Report object using the SetDataSource method. This method requires
three parameters. The first is the data source itself. The second parameter is a
value indicating that the data source you are passing to the report is an ActiveX
data source. This value must be 3. The third is the table you are passing the data
source to. Since you should only have one table defining the structure of the
recordset , this should always be 1. For example:
CRXDatabase.SetDataSource rs, 3, 1
(Create the form, and put CRViewer1 control on it, from any part of your
application you want create an instance of this form, and call InitializeForm
function with 2 parameters – DataSource recordset , and Path to your Report)
Option Explicit
Dim CRXApplication As CRAXDDRT.Application
Dim CRXReport As CRAXDDRT.Report
Dim CRXDatabase As CRAXDDRT.Database
CRViewer1.ReportSource = CRXReport
CRViewer1.ViewReport
Me.Show
End Sub
P.S. These 5 lines of code took 2 days out of my life! So, save your time and say
thanks to me and my boss Dave Raskin who helped me a lot to resolve this problem.
P.P.S. Sorry for the naming conventions, I just wanted to make it looks closer to
Segate examples.