How to use Crystal Reports ActiveX Designer Runtime Library 11.5 in Visual Basic 6.0
Crystal Reports ActiveX Designer Runtime Library 11.5 (CRAXDRT) is a component that allows you to create, modify and preview Crystal Reports in Visual Basic 6.0 applications. It is also known as the Report Creation API (RCAPI) for Visual Basic 6.0. CRAXDRT is not supported in Visual Studio .NET, where you need to use the Report Application Server (RAS) instead.
In this article, we will show you how to use CRAXDRT to create a simple report that displays data from an Access database table. We will also show you how to add a parameter field and a formula field to the report.
Step 1: Add a reference to CRAXDRT
To use CRAXDRT in your Visual Basic 6.0 project, you need to add a reference to the CRAXDRT.dll file. To do this, follow these steps:
Open your Visual Basic 6.0 project or create a new one.
From the Project menu, select References.
In the References dialog box, scroll down and check the box next to Crystal Reports ActiveX Designer Runtime Library 11.5.
Click OK to close the dialog box.
Step 2: Declare a CRAXDRT object and load a report
To create and manipulate a Crystal Report, you need to declare an object of type CRAXDRT.Application and use its methods and properties. You also need to declare an object of type CRAXDRT.Report to hold the report instance. To do this, follow these steps:
In the code window of your Visual Basic 6.0 project, add the following declaration at the top:
Dim crApp As New CRAXDRT.Application
Dim crReport As CRAXDRT.Report
In the Form_Load event of your main form, add the following code to create a new report object and load an existing report file (you can replace the file name with your own):
Set crReport = crApp.NewReport
Step 3: Add a database connection and table to the report
To display data from an Access database table in your report, you need to add a database connection and a table object to the report using the CRAXDRT.DatabaseTables collection. To do this, follow these steps:
In the Form_Load event of your main form, add the following code after loading the report file (you can replace the database path and table name with your own):
'Variables used to setup the database connection
Dim crDBTables As CRAXDRT.DatabaseTables
Dim sDatabasePath As String
Dim sTableName As String
'Get the Tables collection because it has the Add method needed
'to add a connection to the report
Set crDBTables = crReport.Database.Tables
'Set the values for the connection variables
'The full path and name of the Access database
'The database resides in the same directory as the application
sDatabasePath = App.Path & "\xtreme.mdb"
'The name of the Access table
sTableName = "Customer"
'Use the Add method to add the database table to the report
'There are several optional arguments for the Add method
'Which arguments are passed will depend on
'the type of database, the type of table and the type of connection