borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2016 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Passing Param frm 1 subreport to other subrepot)Next Topic (Using an external image and linking it dynamically on a crystal report) New Topic New Poll Post Reply
AndreaVB Forum : Reporting tools : Crystal Report & VB
Poster Message
sanc1
Level: Expert

Registered: 30-09-2003
Posts: 59

icon Crystal Report & VB

Hi Guys!
            Is there any way to create Crystal Reports from VB [runtime]. Suppose runtime we'll attach database to Crystal Report, we'll send diffnt parameters to crystal Report, and so on...
            Hope u guys understand what I mean...  
With Regards...

____________________________
Bite the bit
sanc1@rediffmail.com

31-01-2004 at 02:38 PM
View Profile Send Email to User Show All Posts | Quote Reply
BRMC
Level: Wizard


Registered: 28-11-2003
Posts: 209
icon Re: Crystal Report & VB

Hi,
there are 2 way , one is to put the crystal report viewer (component) in your form and then u should pass a few parameters like connection,db,table,SQLstring and so on and then it show itself the results.
Or by the crystal report components u must have a report with some fields and then u can manage data that u pass by code ,but i don't think u can create new fields by code.

Bye
BRMC

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

04-02-2004 at 01:33 PM
View Profile Send Email to User Show All Posts | Quote Reply
sanc1
Level: Expert

Registered: 30-09-2003
Posts: 59
icon Re: Crystal Report & VB

Hey thanx for the quick suggestion!
                                                   Ya, it's true that through Crystal Report Viewer Components we can initialize the report...but I need to get a bit closer to the problem. Can we create new formula fields...running fields...etc. through VB...
Hope I made myself clear...
looking ahead for ur help guys...

____________________________
Bite the bit
sanc1@rediffmail.com

08-02-2004 at 02:30 PM
View Profile Send Email to User Show All Posts | Quote Reply
BRMC
Level: Wizard


Registered: 28-11-2003
Posts: 209
icon Re: Crystal Report & VB

Hi,
yes some formulas and some fields like title and some running fiel yes , for examle some formula with the property formulas (index) create a formula in crystal report.

i hope this will be useful
bye

BRMC

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

10-02-2004 at 09:18 AM
View Profile Send Email to User Show All Posts | Quote Reply
amitsaxena
Level: Guest

icon Re: Crystal Report & VB

Here is how you can do it

STEPS TO IMPLEMENT CRYSTAL REPORT TO YOUR VB APPLICATION
Using the Active Data Driver
====================================================================
Designing and generating reports using the Crystal Active Data Driver is a straightforward process, but requires several specific steps:
Select the design time data source
Design the Report
Obtain a Recordset from the Runtime Data Source
Open the Report
Pass the Recordset to the Active Data Driver
Print the Report
The following sections demonstrate this process using the Crystal Active Data Driver with the Report Designer Component Automation Server in Visual Basic 6.0.

Select the design time data source
====================================================================
When designing a report for your Visual Basic application, you can specify any ActiveX data source using the Active Data Driver, or you can specify a data definition file so that the actual data is specified at runtime only. The following example uses the sample data definition file included with Crystal Reports:
1. Click New Report in the Crystal Reports Welcome dialog box, or click the New button on the Crystal Reports toolbar.
2. In the Crystal Report Gallery dialog box click Using the Report Expert. In this example, you can click Standard from the Choose an Expert box. Then Click OK.
3. In the Standard Report Expert Dialog box click Database. (OR FOR EXISTING REPORT GO TO MENUE Database/Set Location…)
4. In the Data Explorer dialog box:
expand More Data Sources
expand Active Data  (THIS STEP IS CRUCIAL (!!!!) IT ACTIVATES ActiveDataDriver, if you connect to database other way, you wont be able to use your report from VB environment. The report will not take Recordset as DataSource, will try to get to the Database through report connection, it fails and Message Box “Server not yet opened” will be shown up – this is for SQL Server)
expand Active Data (ADO).
5. In the Select Data Source dialog box click the ODBC (ADO) option, select Xtreme Sample Database from the drop-down list, and then click OK.
6. In the Data Explorer dialog box click Add.
7. In the Select Recordset dialog box select Orders from the Object list, and then click OK.
8. In the Data Explorer dialog box click Close. The Orders table appears as ado in the Tables available for report box, under the data tab, in the Standard Report Expert dialog box.
Note:    For information on specifying an OLE DB provider or other ActiveX data source at design time, see Using ActiveX Data Sources at Design Time.

Design the Report
====================================================================
(Create the report as usual)
Once you have selected a data definition file or an ActiveX data source, you can design your report just as you would design any other report.
1. Click the Fields Tab of the Standard Report Expert.
The data definition file orders appears as a database table in the Database Fields list box. Each of the fields defined in orders.ttx appears as a field in the orders table.
2. Add fields to your report just as you would normally add fields to a report using the Standard Report Expert.
3. Continue designing the report using the Standard Report Expert. When finished, click Design Report. Since the report is based on a data definition file, there is no point in previewing it at this time.
4. Apply any formatting or other changes that you feel are necessary to fine-tune the look of your report. Save the report when finished.
Note:    Before saving your report, be sure to turn off the Save Data with Report option under the File menu. The sample data stored with the data definition file is unnecessary at runtime, and will only increase the size of your report file.

Obtain a Recordset from the Runtime Data Source
====================================================================
(HOW YOU GET THE RECORDSET IS NOT IMPORTANT, WHAT IMPORTANT, THE RECORDSET MUST (!!!!) BE EXACT MIRROR OF YOUR DESIGN-TIME DATABASE TABLE, INCLUDING THE ORDER OF FIELDS !!!!!)

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)

Open the Report
====================================================================
Once you have obtained a Recordset object, you can begin working with the report file you created earlier. This example uses the Report Designer Component Automation Server to open a report file.
Note:    You must add the Report Designer Component Automation Server component to your Visual Basic project before performing the following steps. For complete information on using the Automation Server, see Crystal Report Engine Automation Server.
Declare variables for the Application and Report objects that you will obtain from the Report Designer Component Object Library in the automation server. This can be handled in the declarations section of a form or module.

Dim CRXApplication As New Craxdrt.Application
Dim CRXReport As Craxdrt.Report

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)

Pass the Recordset to the Active Data Driver
====================================================================
The Recordset object gets passed to the Active Data Driver through the SetDataSource method of the Database object in the Report Designer Component Object Library. You must first obtain a Database object from the Report object, then you must use the SetDataSource method to set the report to point at the recordset object for your Active data source. The Report Designer Component Automation Server uses the Active Data Driver itself to replace the data definition file, at runtime, with the Active data source.
The following code demonstrates how to obtain a Database object from the Report object:

Dim CRXDatabase As Craxdrt.Database
Set CRXDatabase = CRXReport.Database

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

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:
CRXReport.PrintOut
Once the data source has been set in the report object, runtime reporting can proceed normally. All features of the Report Designer Component are available to you. See Report Designer Component Object Model for more information


Or show the Report (I would prefer this way more)
====================================================================

(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

Private Sub Form_Load()
    Me.WindowState = 2 'Maximized
End Sub

Private Sub Form_Resize()
    rptCRViewer.Top = 0
    rptCRViewer.Left = 0
    rptCRViewer.Height = ScaleHeight
    rptCRViewer.Width = ScaleWidth
End Sub

Public Sub InitializeForm(rs As ADODB.Recordset, Path As String)
    Set CRXApplication = New CRAXDDRT.Application
    Set CRXReport = New CRAXDDRT.Report
    Set CRXDatabase = CRXReport.Database

    Set CRXReport = CRXApplication.OpenReport(Path, 1)
    CRXDatabase.SetDataSource rs, 3, 1

    CRViewer1.ReportSource = CRXReport
    CRViewer1.ViewReport
    Me.Show
End Sub

15-09-2004 at 08:17 PM
| Quote Reply
tyreejp
Level: Trainee

Registered: 02-06-2005
Posts: 1
icon Re: Crystal Report & VB

Does anyone know if it's possible to design a report using an ODBC(RDO) connection, but then switch gears in your VB.NET code and specify OLEDB(ADO) or Native(SQL Server) database login credentials at run time?


____________________________
---
James

02-06-2005 at 01:05 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1652
icon Re: Crystal Report & VB

YOu should investigate CRAXDRT.Database object. There are methods like AddOleDBSource, LogOnServer, SetDatasource, etc. (I believe they are called like this). I usually set in report the exact provider and only change database location in code.

Maybe it could be also done with ConnectionProperties object, where you can set connection string. Something like

    
For Each tbl In rpt.Database.Tables
        
        Dim CP As CRAXDRT.ConnectionProperties
        
        Set CP = tbl.ConnectionProperties
        
        CP.Item("Connection string") = strConnestionstring

    Next tbl


____________________________
If you find the answer helpful, please mark this topic as solved.

02-06-2005 at 08:29 PM
View Profile Send Email to User Show All Posts | Quote Reply
Ramya
Level: Expert

Registered: 08-04-2005
Posts: 59
icon Re: Crystal Report & VB

Hai
I really apologise to crosspost in this.Yet i have a doubt.

In the above said method u r assigning the table to report at design time.In tried it and i was ok with it.But in some cases i may take values from one or mroe tables and do some calculations in it and then i have to show in report.The cauclutaion part doesnt mean with numerics yet it may depends on the table as whther more querying is requireed.In suhc cases what i expected is to directly assign a table frm VB itself.How to do this
Or else the method of assiging the tabel to  report at deisgn time how to do the calcultaions.

I already started it as a seperate thread yet i need to know more info about it     

27-06-2005 at 12:23 PM
View Profile Send Email to User Show All Posts | Quote Reply
atam1971
Level: Trainee

Registered: 22-02-2009
Posts: 1
icon Re: Crystal Report & VB

quote:
sanc1 wrote:
Hi Guys!
            Is there any way to create Crystal Reports from VB [runtime]. Suppose runtime we'll attach database to Crystal Report, we'll send diffnt parameters to crystal Report, and so on...
            Hope u guys understand what I mean...  
With Regards...



____________________________
atamprakash
22-02-2009 at 06:14 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Reporting tools : Crystal Report & VB
Previous Topic (Passing Param frm 1 subreport to other subrepot)Next Topic (Using an external image and linking it dynamically on a crystal report) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2016 Andrea Tincaniborder