pass parameter from vb6 to crystal report 8.5

db , vb6 United States
  • 9 years ago
    hi,
    i am new to the crystal report(self learning), may i know how to pass a parameter to a crystal report 8.5 when the user check on certain checkbox in vb6 and generate the specify group of record .thanks..sample coding or related link may help me understand better ...thanks a lots..
  • 9 years ago
    The following is an edited extract from a Wrapper Class we developed to handle Crystal at runtime.
    It shows how we set parameters.
    Hope it helps.

    Regards

    Geoff

    ' ' Crystal Report Wrapper Class
    

    ' Declares
    Dim oCrystalApp As CRAXDRT.application
    Dim oCrystalReport As CRAXDRT.Report
    Dim oCrystalParameters As CRAXDRT.ParameterFieldDefinitions
    Dim oCrystalParameter As CRAXDRT.ParameterFieldDefinition

    ' Open the report
    Public Sub OpenReport(cReportName as string)
    Set oCrystalReport = oCrystalApp.OpenReport(cReportName, crOpenReportByTempCopy)
    Set oCrystalParameters = oCrystalReport.ParameterFields
    End Sub

    'Set Parameters
    Public Sub SetParameter(cParmName as string, cParmValue as string)
    For Each oCrystalParameter In oCrystalParameters
       If oCrystalParameter.Name = cParmName  Then
           Select Case oCrystalParameter.ValueType
               Case crDateField, crDateTimeField, crDateField
                   oCrystalParameter.SetCurrentValue CDate(cParmValue)
               Case crNumberField
                   oCrystalParameter.SetCurrentValue Val(cParmValue)
               Case Else
                   oCrystalParameter.SetCurrentValue cParmValue & ""
           End Select
       End If
    Next oCrystalParameter
    End Sub

  • 9 years ago
    thanks a million Geoff, i appreciate a lots!!
  • 9 years ago

    I did follow what you instructed but when i run, the dialog apear to prompt
    me fill the value of parameter.
    Pls help me

  • 9 years ago

    Hi all,
    I use vb6 & crystal report 8.5 (8.rpt)
    but i cannot pass parameter


    Public crxApplication As New CRAXDRT.Application
    Public CrxReport As New CRAXDRT.Report
    Dim CrtParameters As CRAXDRT.ParameterFieldDefinitions
    Dim CrtParameter As CRAXDRT.ParameterFieldDefinition


    Private Sub PrintReport()
    Dim ReportName  As String
    Dim i As Integer
    Dim cParmValue  As String
    cParmValue = "Me kiep"
    ReportName = App.Path & "\RPT\BillControlZ.rpt"
    Set CrxReport = crxApplication.OpenReport(ReportName, crOpenReportByTempCopy)
    Dim CRTABLE As CRAXDRT.DatabaseTable
    i = 1
    For i = 1 To CrxReport.Database.Tables.Count
    Set CRTABLE = CrxReport.Database.Tables.Item(1)
    CRTABLE.SetLogOnInfo gODBCName, gDBDatabaseName, gDBUserName, gDBPassword
    Next i


    CrxReport.EnableParameterPrompting = False
    Set CrtParameters = CrxReport.ParameterFields
    For Each CrtParameter In CrtParameters
      If CrtParameter.Name = "{?strTemp}" Then
         CrtParameter.AddCurrentValue cParmValue
      End If
    Next CrtParameter


    CRViewer1.Visible = True
    CrxReport.DisplayProgressDialog = True
    CrxReport.VerifyOnEveryPrint = True
    CrxReport.UseIndexForSpeed = True
    CrxReport.SQLQueryString = strSQL & " order by SalePoint "
    CRViewer1.ReportSource = CrxReport
    CrxReport.VerifyOnEveryPrint = True
    CrxReport.DiscardSavedData
    CRViewer1.DisplayGroupTree = False
    CRViewer1.ViewReport
    CRViewer1.ShowFirstPage
    CRViewer1.Zoom 100
    Screen.MousePointer = vbDefault
    cmdView.Visible = True
    cmdPrinter.Visible = True
    End Sub
    When i run the report.
    "{?strTemp}" parameter is not showed on report
    Help me pls.


  • 9 years ago


    Code:
    If CrtParameter.Name = "{?strTemp}" Then


    Why the {braces} ?


    Try


    Code:


     If CrtParameter.Name = "?strTemp" Then
        CrtParameter.AddCurrentValue cParmValue
     End If


  • 8 years ago


    Hi, thanks for help
    I run debug and use immediate window i typed
    ?CrtParameter.Name  
     "{?strTemp}"
    strTemp is a paramater that I  create in crystal report
    when I run debug the code line
        CrtParameter.AddCurrentValue cParmValue
    is executed
    But when the report open  strTemp disppear or its value is empty
    Help me Pls

  • 8 years ago


    Yes, you are right about the {braces} - my mistake.


    Try SetCurrentValue instead of AddCurrentValue.


    Code:

    If CrtParameter.Name = "{?strTemp}" Then
       CrtParameter.SetCurrentValue cParmValue
    End If


  • 8 years ago
    Thanks for your kinds
    I try SetCurrentValue
    But when the report open  strTemp disppear or its value is empty

  • 5 years ago

    GeoffAtDatagaard,

    Just a reminder.  Remember to 'Set' the 'oCrystalApp' instance.  You didn't do that, and it will throw an error.  Here's what you should have somewhere in your code:
            Set oCrystalApp = New CRAXDRT.Application

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” - Bill Gates