[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

create crystal report in vb runtime

Posted on 2005-04-28
16
Medium Priority
?
3,397 Views
Last Modified: 2011-10-03
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:
Option Explicit

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
'control.
'=====================
Private Sub Form_Load()

Set crApplication = New CRAXDRT.Application
Set crReport = crApplication.NewReport

Call AddADOCommand
'Call AddToDetails

CRViewer1.ReportSource = crReport
CRViewer1.ViewReport

End Sub

'=====================
'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'
'table.
'
'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()

With ADOcn
.Provider = "MSDASQL"
.ConnectionString = "DSN=Xtreme Sample Database"
.CursorLocation = adUseClient
.Open
End With

'Create an instance of a Recordset object
Set ADOrs = New ADODB.Recordset
With ADOrs
.ActiveConnection = ADOcn
.CursorType = adOpenDynamic
.Open "Select * From Customer"
End With

'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

End Sub



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!
0
Comment
Question by:jellyfizme
  • 8
  • 6
14 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 13887554
I don't see where you have included the Report Creation API.

How was the report created?

mlmcc
0
 

Author Comment

by:jellyfizme
ID: 13895480
I didnt include all the code here.. but I already received the error of "Server not yet opened" during the execution of Public Sub AddADOCommand() .. where :

crReport.Database.AddADOCommand ADOrs.ActiveConnection, ADOrs.ActiveCommand

I wonder why? izzit we must hav p2smon.dll?? I dun hav it in my pc.. neither can I download from the internet... none of the link is usefull.. :(

Pls help..
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 101

Expert Comment

by:mlmcc
ID: 13898689
Can you do an update install of Crystal to add the database method?

mlmcc
0
 

Author Comment

by:jellyfizme
ID: 13899908
how?
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 13900495
Insert the CR CD and select CUSTOM
Add the ADO database drivers

mlmcc
0
 

Author Comment

by:jellyfizme
ID: 13903107
Ok.. I'll repeat clearly my questin this time.. sorry for confusing..
----------------------------------------------------------------------------------------------
Option Explicit
Dim crApplication As CRAXDRT.Application
Dim crReport As CRAXDRT.Report
Dim ADOrs As ADODB.Recordset
Dim ADOcn As New ADODB.Connection
------------------------------
Private Sub Form_Load()
Set crApplication = New CRAXDRT.Application
Set crReport = crApplication.NewReport

Call AddADOCommand
Call AddToDetails

CRViewer1.ReportSource = crReport
CRViewer1.ViewReport
End Sub
------------------------------
Public Sub AddADOCommand()
With ADOcn
.Provider = "MSDASQL"
.ConnectionString = "DSN=Xtreme Sample Database"
.CursorLocation = adUseClient
.Open
End With

Set ADOrs = New ADODB.Recordset
With ADOrs
.ActiveConnection = ADOcn
.CursorType = adOpenDynamic
.Open "Select * From Customer"
End With

crReport.Database.AddADOCommand ADOrs.ActiveConnection, ADOrs.ActiveCommand
End Sub
--------------------------------------------------
Public Sub AddToDetails()
Dim crSection As CRAXDRT.Section
Dim crFieldObject As CRAXDRT.FieldObject

Set crSection = crReport.Sections.Item("D")
Set crFieldObject = crSection.AddFieldObject("{ado.Customer Name}", 600, 0)
Set crFieldObject = crSection.AddFieldObject("{ado.Last Year's Sales}", 3720, 0)
End Sub
-----------------------------------------------------
Private Sub Form_Resize()
With CRViewer1
.Top = 0
.Left = 0
.Width = Me.ScaleWidth
.Height = Me.ScaleHeight
End With
End Sub
----------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
Set crReport = Nothing
Set crApplication = Nothing
End Sub
----------------------------------------------------
These are the reference 'n component I've add :
1. Crystal Report 8.5 ActiveX Designer Run Time Library (reference)
2. Crystal Report Viewer Control (for reference & component)
3. Microsoft ActiveX Data Objects 2.8 Library (reference)

When I compile the program, this is the error:
Run-time error '-2147192184(800047288)':
Server has not yet been opened.

I dun wat is the cause of this error.. Search all the site.. Their code is same as mine.. Already wasting a lot of time doing searching.. :(
Pls give me any idea to solve it... (already reinstall CR 'n patch with the latest service pack3)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 13903419
Have you looked at this article

http://support.businessobjects.com/communityCS/TechnicalPapers/cr_server_not_yet_been_opened.pdf.asp

Does the report open in the Crystal designer?

DId you build it usig an ADO connection to the database?

mlmcc
0
 

Author Comment

by:jellyfizme
ID: 13903484
yes I already read the pdf.  actually, the ado connection to database is successful.. I've test it. but it stop when it comes to :

crReport.Database.AddADOCommand ADOrs.ActiveConnection, ADOrs.ActiveCommand

saying tat "Server has not yet been opened"..  I wonder could it because of the operating system tat I'm using? (Win XP)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 13905651
How did you build the report?  What database connection did you use?

Crystal has a habit of maintaining the original connection and when you open the report it tries to make that connection.

mlmcc
0
 

Accepted Solution

by:
jellyfizme earned 0 total points
ID: 13923507
Ok I've done with it..
I only change a bit in then code to make it run..

From: crReport.Database.AddADOCommand ADOrs.ActiveConnection, ADOrs.ActiveCommand
To: crReport.Database.AddOLEDBSource ADOrs.ActiveConnection, ADOrs.ActiveCommand

Thanks anyway!
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 13923712
Obviously you built the report using an OLE datasource rather than an ADO datasource.  That is what I was trying to elicit from you but obviously we weren't communicating very well.  

mlmcc
0
 

Author Comment

by:jellyfizme
ID: 13944401
can I get back my points? bcoz I hav anonther question to ask :D

Sorry for any inconvenient cause by me..
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 14004093
Points refunded and last comment by asker was accepted.

mlmcc
Crystal Page Editor
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question