Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Crystal Reports 8.5 in VB6

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hi all.
I've got a program that I'm trying to connect to a pre-built Crystal Report.

I'm using the CRViewer object.
I'm referenceing the 'Crystal Report Viewer Control'
& 'Crystal Reports 8.5 ActiveX Designer Runtime Library'

I'm trying to use a query to feed the report because the LogOnServer method seems twitchy and I would like to feed a variable to the query.

The report is prebuilt so I copied the query out of the Database->Show SQL Query menu... and used that in the program. I got the expected recordset. Now I need to feed that recordSet to the CRViewer. This happens..

It asks for a parameter that I gave it in the query and then tries to log on to the database which produces the error ..Server has not yet been opened....

I don't need it to do this because I already have the recordset. What do I need to do to get the report to use the query instead of trying to log on to the server?
Some setting in the pre-built report? Some method of CRViewer I missed? The code is below if you are interested.
Thanks everyone.
PB
CODE
'////////////////////////////////////////////
Public Appn As CRAXDRT.Application
Public cReport As CRAXDRT.Report

Private Sub Command1_Click()
'Get recordSet
Dim objCmd As ADODB.Command
Dim objRec As ADODB.Recordset
'Yada yada yada get the recordset code
'...I debug print the recordset so
'...I know it works
'/////////////////////////////////////
'Report

Set Appn = CreateObject("CrystalRunTime.Application")

'sets the pre-constructed report path
Set cReport = Appn.OpenReport("C:\Program Files\Display Board\PmWorkOrder.rpt")

cReport.DiscardSavedData

cReport.Database.SetDataSource objRec

CRViewer1.ReportSource = cReport
CRViewer1.ViewReport

End Sub
 
You know, I've had alot of problems with CR in my day *cough CRPE32.dll cough* and I've found it best to create a report database that has diffrent tables depending on what report I'm printing. That way, I can link my report directly to the ReportDatabase/ReportTable and not have to worry about filtering the records through CR.

So in my Print Modual I call "FilterRecords" before the actual print command. My FilterRecords modual then opens up both databases (Main and Report) and grabs the required records from Main and passes them to Report. That way, I can just tell CR to print that report and not have to worry about filtering, since the only data in the ReportDatabase-Table is what needs to be printed. Just remember, if you choose to do this you must "DELETE FROM ReportTable" at the start of the Filter sub or you'll just keep adding records and not replaceing them.

Peace
-N473
 
Great!!! That sounds really useful. Now that I have the report table... how do I point my Report to it???? Sorry to be dense, I've just never tried to get Crystal to work 'inside' an app before.
PB
 
check the FAQs for crystal reports i have posted the sample there hope it will help u.

Harshu.
 

This line will just clear all pre-set values
CrxRpt.RecordSelectionFormula = ""


The answer to your question.
CrxRpt.Database.Tables(1).SetLogOnInfo ServerName, DBName, LogonUser, LogonPassword
CrxRpt.Database.Tables(1).Location = NewTableName

[flowerface]

"All I ask is the chance to prove that money can't make me happy." - Spike Milligan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top