pass parameter from vb6 to crystal report 8.5

db , vb6 United States
  • 12 years ago
    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..
  • 12 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.



    ' ' 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

  • 12 years ago
    thanks a million Geoff, i appreciate a lots!!
  • 12 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

  • 12 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
    CRViewer1.DisplayGroupTree = False
    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.

  • 12 years ago

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

    Why the {braces} ?



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

  • 12 years ago

    Hi, thanks for help
    I run debug and use immediate window i typed
    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

  • 12 years ago

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

    Try SetCurrentValue instead of AddCurrentValue.


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

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

  • 9 years ago


    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).


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.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra