Hi,
Please guide us how to call crystal report into visual basic.
ASM
Printable View
Hi,
Please guide us how to call crystal report into visual basic.
ASM
I have a short example in my signature - "VB6/Crystal Report Ex." ;)
Hi
I have gone through your example coding... and try accordingly
but i can not find crystal reports reference in vb6 project-Reference..
please guide me...
ASM
Hi
I have gone trhough your example but I can not get project-reference
for crystal reports you have mention...
Thanks
Hi ASM,
Hope you are not frustrated by now!
I went thru the same questions that you have.
Here is my sample code:
VB Code:
Private Sub Command2_Click() Dim path As String Dim reportname As String path = "ReportPath\" reportname = "ReportName.rpt" Dim oApp As CRAXDRT.Application Dim oReport As CRAXDRT.Report Dim ors As dao.Recordset Dim ssql As String Set oApp = New CRAXDRT.Application Set oReport = oApp.OpenReport(path & reportname) CRViewer91.ReportSource = oReport CRViewer91.ViewReport Screen.MousePointer = vbDefault End Sub
Couple things:
Make sure you have Crystal Viewer installed. I think there is one common viewer for any kind of reports.
Once you do that, include 'Crystal Viewer 9.0 ActiveX designers....' reference in to your vb project.
After above two steps, you will have access to CRAXDRT library.
Thanks RobDog for the code.
Ankeet.
The references are available if you have Crystal Reports installed. Do you have a copy of the program? The references might vary a little on newer versions of CR but should still be visible.Quote:
Originally Posted by asm
The CR Viewer control is only available if you have CR installeed on your system.
Your Welcome, ankeet1. Glad it has helped as it doesnt get much notice. :(
:)
RobDog,
Your code works well, I can open report i can even execute this line
but, when the report opens, it still prompts me for parameters. How do i stop this?!!VB Code:
oReport.Database.SetDataSource oRs, 3, 1
Ankeet
That is caused by the report file itself. Open it up on the Crystal Report designer, and remove the part that calls for parameters.
Ok, in your report in Crystal Reports you must have created some parameters? You need to pass these parameters before you open the report using the Parameters collection.
Yes,
when i created the reports, I did have a stored proc set as data source and that stored proc expects parameters.
There is no place else in the report which uses any of these parameters. I do have calculated fields (formulas) but they are calculated based on grouping and values from the stored proc.
Also,
robDog, can you point me to some place which demonstrates using the Parameters collection.
I followed one of the posts and tried to pass 'discrete' parameters in following way:
But, when i type 'oReport.' there is no drop down list which means, i might need to include some more references. Which ones?VB Code:
crParameterFieldDefs = oReport.DataDefinition.ParameterFields
Your help is GREATLY appreciated!
Ankeet
oReport is my Report object. There should be a Parameters collection right off of the Report object. DataDefinition is for using ttx files with CR.
Guys once again!
A'ight, i fixed the previous issue of passing parameters. Now it does not ask me for param values. Below is the code.
Also, as you can see from the code, i use a WHILE loop to open multiple reports. Thats where the problem is - how do i open multiple reports (tabbed browsing)?
VB Code:
While Not de.rsdbo_spMES_GetSelectedReports.EOF Set oApp = New CRAXDRT.Application Set oReport = oApp.OpenReport(App.Path & "\Reports\" & _ de.rsdbo_spMES_GetSelectedReports.Fields("CSName").Value) ' CALL the modReportViewer. ' Pass the report name, based on which the modReportViewer ' will call appropriate report wrappers and return a ' record set. oReport.DiscardSavedData 'oReport.Database.SetDataSource ReportFetcher(de.rsdbo_spMES_GetSelectedReports.Fields("CSName").Value), 3, 1 ' get the count of parameter fields in the current report ParamCount = oReport.ParameterFields.Count ' loop for number times = param count. ' Also make sure EVERY STORED PROC SHOULD USE SAME NAME FOR PARAMETERS. ' ANY NEW PARAMETER SHOULD BE ADDED TO THE CASE STATEMENT. For i = 1 To ParamCount Select Case LCase(oReport.ParameterFields(i).ParameterFieldName) Case LCase("@CurrentRepCompany") oReport.ParameterFields(i).AddCurrentValue (gCompany) Case LCase("@CurrentRepPlantID") oReport.ParameterFields(i).AddCurrentValue (gPlantID) Case LCase("@CurrentRepDepartmentID") oReport.ParameterFields(i).AddCurrentValue (gDepartmentID) Case LCase("@CurrentRepLineID") oReport.ParameterFields(i).AddCurrentValue (gLineID) Case LCase("@CurrentRepItemID") oReport.ParameterFields(i).AddCurrentValue (gItemID) Case LCase("@CurrentRepProdDate") oReport.ParameterFields(i).AddCurrentValue (CDate(gBeginDate & " 00:00")) Case LCase("@CurrentRepEndDate") oReport.ParameterFields(i).AddCurrentValue (CDate(gEndDate & " 00:00")) Case LCase("@CurrentUser") oReport.ParameterFields(i).AddCurrentValue (gCurrentUserID) End Select Next i ' do not let the user refresh the data on the report. ' user can close the report and open it again. crViewer.EnableRefreshButton = False ' display tabs. crViewer.DisplayTabs = True crViewer.TabIndex crViewer.ReportSource = oReport crViewer.ViewReport Screen.MousePointer = vbDefault de.rsdbo_spMES_GetSelectedReports.MoveNext Wend
Thanx for your help!
Ankeet