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
You can pass any value you want to CR, whether the user typed it or your program generated it in this way.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
(Parameters that begin with @ are for use with stored procedures)




Reply With Quote