Results 1 to 5 of 5

Thread: [RESOLVED] Crystal Reports 9.2 and Stored Procedures problem

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    59

    Resolved [RESOLVED] Crystal Reports 9.2 and Stored Procedures problem

    Hi, before making my question, I'm working with:
    VB6
    Crystal Reports 9.2.2.693
    SQL Server
    I need to connect via OLEDB

    Ok, I have setup my report all from within the report. The database, the stored procedure, and the fields I'm going to display.

    My question is: How can I do to display the report by passing the parameters through VB6?

    I already have added Crystal Reports 9 ActiveX Designer RunTime Library and Crystal Reports Viewer 9 to References as well as Crystal Report Viewer 9 to Components.

    Hope you can help me figure this out.

    Marcelo.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Crystal Reports 9.2 and Stored Procedures problem

    Use the CRAXDRT objects to set the parameters (and anything else you need, like login information).

    This sample code Opens, Sets two Parameters and then Shows the report on a Form that contains the Crystal Viewer control. In this case the two parameters are "Discrete" Date values that the user chosen from Date Picker controls.

    VB Code:
    1. Dim objCrystal As CRAXDRT.Application 'its better to create this object global to the VB application.
    2.     Dim objReport As CRAXDRT.Report
    3.     Dim objParam As CRAXDRT.ParameterFieldDefinition
    4.  
    5.     Set objCrystal = New CRAXDRT.Application
    6.     Set objReport = objCrystal.OpenReport(FileName, 1)
    7.  
    8.     Set objParam = objReport.ParameterFields.GetItemByName("@FromDate")
    9.     objParam.ClearCurrentValueAndRange
    10.     objParam.AddCurrentValue dtpFromDate.Value
    11.    
    12.     Set objParam = objReport.ParameterFields.GetItemByName("@ToDate")
    13.     objParam.ClearCurrentValueAndRange
    14.     objParam.AddCurrentValue dtpToDate.Value
    15.    
    16.     With frmReportViewer
    17.         If Len(ReportTitle) > 0 Then
    18.             .Caption = ReportTitle
    19.         End If
    20.         .ReportViewer.ReportSource = objReport
    21.         .ReportViewer.ViewReport
    22.         .Show
    23.         .ZOrder vbBringToFront
    24.     End With

    Note I only have Crystal 8.5 but the code should be similar for 9.

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    59

    Re: Crystal Reports 9.2 and Stored Procedures problem

    Hi Bruce, I'm trying to figure out your code. And I think that is for filling a report indicating field and value, right?
    But... I already have all parameters setup at the file.rpt report such as database connection, stored procedure (which has a big sql query) and of course the fields resulting from that stored procedure which are set at the report designer.
    This stored procedure accepts two parameters which has nothing to do with fields. They are numeric and they act as follows: if prm1=0 and prm2=0 then do something; if prm1=0 and prm2=1 then do something else... and so on...

    Hope you understand me and can help me figure this out.

    Thanks, Marcelo.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Crystal Reports 9.2 and Stored Procedures problem

    My code shows you how to pass parameter values from a VB 6 application to the Crystal Report and then show the report.

    The Report.ParameterFields collection is used to set the value of the parameters that you created in your rpt file.

    When the line .ReportViewer.ViewReport is called the Crystal Runtime library takes over and the report is generated.

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    59

    Re: Crystal Reports 9.2 and Stored Procedures problem

    Solved it! Thanks!
    Last edited by techuser; Feb 2nd, 2006 at 03:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width