Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal report 9 parameters to subreport

Status
Not open for further replies.

Avacha

Technical User
Apr 1, 2002
69
US
Please help me!
I have a main report and 3 subreports and all 4 reports run off of separate stored procedures. BUT they all require the same parameter to run. Currently, I have 4 parameter prompts to run the main report and the 3 subreports and have to select the same parameter 4 times.
From run time VB 6 i send parameters to SQL stored procedure.
The main report runs fine . But the subreports...
I can not send parameter to subreport.
Any ideas?? Thanks in advance.
 
hi check this out
How do you pass a stored procedure parameter to a report at runtime using the Engine Object model?


Solution

To pass a stored procedure parameter to a report, use the following sample code:

====================
NOTE:

This sample Windows application uses the Windows Forms viewer. The sample has one form (Form1) that contains the viewer. The report code is run from the form's constructor (Public Sub New( )).
====================

'Add the following lines of code to the top of the code page to import the relevant 'namespaces

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class Form1
Inherits System.Windows.Forms.Form

'Crystal Reports Variables
Dim oRpt As New CrystalReport1() 'This is a strongly typed report being used
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo()
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

' Set the Connection parameters
' Using an OLEDB connection to a SQL Sever DB (Database: Pubs)
With crConnectionInfo
.DatabaseName = "DBName"
.ServerName = "ServerNameOrODBCName"
.UserID = "UserID"
.Password = "Password"
End With

crTables = oRpt.Database.Tables

'Set the logon information for each table.

For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

'*****************************
' Pass the Stored Procedure parameter to the report
'*****************************

'Get the collection of parameters from the report
crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields

'Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions.Item("@percentage")

'Get the current values from the parameter field. At this point
'there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues

'Set the current values for the numeric parameter field
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = "50"

'Add the current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue)

'The current parameter values must be applied for the parameter field.
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

CrystalReportViewer1.ReportSource = oRpt

End Sub



if more help need then use this link

cheers

pgtek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top