Visual Studio 2019, Crystal Reports 14, Sub Report, Incorrect Paramater

  • Thread starter Thread starter SoftSpot
  • Start date Start date
S

SoftSpot

Guest
Hi,

I created a report with one sub report in it. When I preview the report in Crystal Reports, all is working perfect.

The moment I fire the report from my VB code to preview the report in CRViewer, I am getting a message "The paramater is incorrect". My sub report is linked to the main report and If I preview in crystal all is fine, included the data.

glbReport = App_Path() & "Reports\Pick.rpt"
glbFmlaText = "{picklist.cpnyid} = '" & glbCpnyId & "' and {picklist.pastelref} = '" & sKey & "' "
report.Load(glbReport, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
frmReport.ViewReport(glbReport, glbFmlaText, "")
frmReport.ShowDialog()


Friend Function ViewReport(ByVal sReportName As String, Optional ByVal sSelectionFormula As String = "", Optional ByVal param As String = "") As Boolean
Dim intCounter As Integer
Dim intCounter1 As Integer

Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument


Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue


Dim currValue As CrystalDecisions.Shared.ParameterValues


Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject


Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument



Dim strParValPair() As String
Dim strVal() As String
Dim index As Integer

CrConn = New CrystalDecisions.Shared.ConnectionInfo
CrConn.ServerName = sServer
CrConn.DatabaseName = sDatabase
CrConn.IntegratedSecurity = True

ConInfo = New CrystalDecisions.Shared.TableLogOnInfo
ConInfo.ConnectionInfo = CrConn

Try

'Load the report
objReport.Load(sReportName, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
'objReport.DataSourceConnections
intCounter = objReport.DataDefinition.ParameterFields.Count

If intCounter > 0 Then
'to see id date selection was made
Dim parFields As New CrystalDecisions.Shared.ParameterFields
Dim parField As New CrystalDecisions.Shared.ParameterField
Dim parRange As New CrystalDecisions.Shared.ParameterDiscreteValue

parField.ParameterFieldName = "ReportDates" ' Parameter Name In Crystal Report
parRange.Value = glbFormula ' value For Parameter Field
parField.CurrentValues.Add(parRange)
parFields.Add(parField) ' To add parameter in parameterslist
crViewer.ParameterFieldInfo = parFields
End If



If intCounter = 1 Then
If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then
intCounter = 0
End If
End If

'Paramaters

If intCounter > 0 And Trim(param) <> "" Then
strParValPair = param.Split("&")

For index = 0 To UBound(strParValPair)
If InStr(strParValPair(index), "=") > 0 Then
strVal = strParValPair(index).Split("=")
paraValue.Value = strVal(1)
currValue = objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues
currValue.Add(paraValue)
objReport.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(currValue)
End If
Next
End If



For intCounter = 0 To objReport.Database.Tables.Count - 1
objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
Next



For index = 0 To objReport.ReportDefinition.Sections.Count - 1
For intCounter = 0 To objReport.ReportDefinition.Sections(index).ReportObjects.Count - 1
With objReport.ReportDefinition.Sections(index)
If .ReportObjects(intCounter).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportObject)
mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo)
Next

End If
End With
Next
Next


If sSelectionFormula.Length > 0 Then
objReport.RecordSelectionFormula = sSelectionFormula
End If

crViewer.ReportSource = Nothing

'Set the current report object to report.
crViewer.ReportSource = objReport
crViewer.Refresh()

'Show the report
crViewer.Show()
Return True
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Function

1484015.png


Always try something new....dont walk in the shoes of the dead.

Continue reading...
 
Back
Top