Link to home
Start Free TrialLog in
Avatar of mrsompura
mrsompura

asked on

Opening Crystal Report using VB Application

I'm working with crystal report and Visual Basic. I'm using Crystal Report for the first time.

I need help on how to call crystal report file (.rpt) file using Crystal Report Viewer Control using VB Application.

I have added required references to my vb project. I've also created report using Crystal Report and saved it in Report Folder where my application will be installed.

I'm using MS SQL Server as backend. I'm using Crystal Report 8.5.

I have added Crystal Viewer Control in one Form. What code i need to write to open the report without any error and updated data?

Can any one provide me sample application? Please Help. It is urgent. I'm new guy for Crystal Report.

Thanks,

Rakesh Sompura.
Avatar of vidru
vidru

You can get the sample apps here:
http://support.businessobjects.com/communityCS/TechnicalPapers/apps_rdc.pdf.asp

If you're using the RDC, here is the minimum code you need to run a report against SQL Server:

'General Declarations
Dim crxApp As New CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report

Private Sub Form_Load()

'Open the report
Set crxRpt = crxApp.OpenReport(App.Path & "\Reports\Profile.rpt")

'Clear any saved data to force to report to read from the db
crxRpt.DiscardSavedData

'Set the connection for the report.
crxRpt.Database.Tables(1).SetLogOnInfo "ServerOrDSNName", "DBName", "UserID", "Password"

'View the report
CRViewer.ReportSource = crxRpt
CRViewer.ViewReport

-dave
Avatar of Mike McCracken
Looks good.  For deploying if you are using InstallShield there are merge modules to ease the process

http://www.installshield.com/downloads/modules.asp?prod=cx&lan=english&xmlUse=y&xmlUse=y&xmlUse=y

mlmcc
Avatar of mrsompura

ASKER


Thank you for the code. I've written the same code that you have pasted above.

When I'm trying to open the report it gives me the error "Server has not been yet started".

Do you have any idea why it gives this error?

I've created DSN also but still it gives the same error.

One More thing i want to ask that Which type of database i need to choose while creating reprot in Crystal Report 8.5?

Do I need to choose ODBC or SQL Server Database from More Database Option.

I'm using Crystal Report Expert and Standard Report Format.

Please Help!

Thx,

Rakesh Sompura

ASKER CERTIFIED SOLUTION
Avatar of vidru
vidru

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The other option you could look at is to use an OLE connection.  The code dave supplied will still work but you don't need to setup the ODBC connection or have the SQL client.

mlmcc
Thank you very much vidru for helping me out.

Some how With the help of you and one of my colleague, I've sovled the problem.

If anything will be there next time.... I expect the such good response from you people.

Thanks a lot once again.

Rakesh Sompura
Nosotros tenemos los reportes en Crystal Report 8.5 los reportes los tenemos conectados directamente con Database Files haciendo referencia a una base de datos directa en Access. Este reporte queremos que lo genere tanto para Access como para SQL Server.  Que debemos hacer.  Hay que cambiarle la conexion en algun lado para que me genere los reportes en SQL Server????

Al darle la conexion con el reporte siempre saca los datos existentes en la base de datos de Access.  Que debemos hacer para que me saque los datos existentes en SQL Server.

crxRpt.Database.Tables(1).SetLogOnInfo "ServerOrDSNName", "DBName", "UserID", "Password"

Por favor, necesitamos una pronta solucion

We have the reports in Crystal Report 8.5 the reports have them connected directly with Database Files referring to a direct base of information in Access. This report we want that it(he,she) generates it both for Access and for SQL Server. That we must do. Is it necessary to change the connection in algun side in order that it(he,she) me generates the reports in SQL Server????

On having given the connection to him with the report always it(he,she) extracts the existing information in the base of information of Access. That we must do in order that it(he,she) me extracts the existing information in SQL Server.

CrxRpt. Database. Tables (1) .SetLogOnInfo "ServerOrDSNName", "DBName", "UserID", "Password"
Please, we need a prompt solution
i have designed a report in crystal Reports11, it runs ok in CR preview.
How can i run that report. Would you please tell met the code for VB 6 to open that report.


Thanks