Results 1 to 7 of 7

Thread: [RESOLVED] Pass Date Parameters from VB6 to CR XI

Threaded View

  1. #5
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Pass Date Parameters from VB6 to CR XI

    Anyway, I forgot to show how to pass parameters to rpt from vb6 app
    The rpt read data from a sql server (it doesn't matter) but could be from any db

    References:
    Crystal Reports Viewer Control
    Crystal Reports ActiveX Designer Run Time Library
    Code:
    ' Typical Variable Declarations
    dim crApp as New CRAXDRT.Application
    dim crRept as New CRAXDRT.Report
    dim crParamDefs as CRAXDRT.ParameterFieldDefinitions
    dim crParamDef as CRAXDRT.ParameterFieldDefiniton
    dim crDBTab as CRAXDRT.DatabaseTable
    
    ' Open Report File
    set crRept = crApp.OpenReport("WHATEVER.RPT")
    
    ' Logon to SQL server
    crRept.Database.LogonServer "p2ssql.dll", "server name", "database name", "userid", "userpassword"
    
    ' Set table locations (because my reports run against multiple servers)
    foreach crDBTab in crRep.Database.Tables
      crDBTab.SetLogonInfo "server name", "database name", "userid", "userpassword"
    next
    
    ' Disable Parameter Prompting for the end user
    crRep.EnableParameterPrompting = FALSE
    
    ' Gather the list of available parameters from the report
    set crParamDefs = crRep.ParameterFields
    
    ' Loop through all parameters in the report by name, filling in the appropriate parameter with the right value
    foreach crParamDef in crParamDefs
      select case crParamDef.ParameterFieldName
        case "SubTitle"
          crParamDef.SetCurrentValue "My Report Subtitle Goes Here"
        case "@BeginDate"
          crParamDef.SetCurrentValue datevalue(txtBeginDate)
        case "@EndDate"
          crParamDef.SetCurrentValue datevalue(txtEndDate)
        case "@IntegerParam"
          crParamDef.SetCurrentValue val(int(txtIntegerParam))
      end select
    next
    crViewer1.ReportSource = crRept
    crViewer1.viewReport
    You can pass any value you want to CR, whether the user typed it or your program generated it in this way.
    (Parameters that begin with @ are for use with stored procedures)
    Last edited by jggtz; Apr 10th, 2013 at 05:25 PM.
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

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