create crystal report in vb runtime
Posted on 2005-04-28
I would like to create a program with vb6 & crystal report 8.5 where a user is free to select a particular field to be shown in the report. fields from table will be listed on vb form. user only need to check the require field 'n click generate to show a report. Most of the site recommend ADO & Record Creation API.
This is the code I get:
Dim crApplication As CRAXDRT.Application
Dim crReport As CRAXDRT.Report
Dim ADOrs As ADODB.Recordset
Dim ADOcn As New ADODB.Connection
'The Form_Load event creates an instance of the RDC engine,
'then makes calls to routines that will setup the report and
'finally display the report in the Crystal Report Viewer
Private Sub Form_Load()
Set crApplication = New CRAXDRT.Application
Set crReport = crApplication.NewReport
CRViewer1.ReportSource = crReport
'The AddADOCommand() routine is used to add an Active Data
'database connection to the sample database, Xtreme.MDB. In
'this sample only 1 table is being used, which is the 'Customer'
'An ADO Connection object is first used to create the
'connection to the database. The connection is using ODBC
'to connect to the sample Crystal Reports data source. Then
'a Recordset object is used to create the data for the report.
Public Sub AddADOCommand()
.Provider = "MSDASQL"
.ConnectionString = "DSN=Xtreme Sample Database"
.CursorLocation = adUseClient
'Create an instance of a Recordset object
Set ADOrs = New ADODB.Recordset
.ActiveConnection = ADOcn
.CursorType = adOpenDynamic
.Open "Select * From Customer"
'This will add a data source to the report.
'The pConnection parameter is set to the recordset's active connection
'The pCommand parameter is set to the recordset's active command object
crReport.Database.AddADOCommand ADOrs.ActiveConnection, ADOrs.ActiveCommand
I'm facing problem with the command in last line.. in which an error of "Server has not yet been opened" is pop up. I wonder why this could happen.. Some of the solution suggest tat I'm missing of "p2smon.dll". Can't find the require dll file. can someone send me over?
Actually, I dun really like DSN connection. Do we hav better ways of doing tat?
For those who really try to answer this question, I really appreciate that.. thank you!