on 2018 May 09 10:09 PM
Several years ago in a previous version of Crystal Reports the optional prompt did not work properly and I had to set values to zero and test for that rather than using the HasValue function. I recently upgraded to v22 and now find all of my reports with parameters that support a list of values are now prompting the user for values, even when the list has values in it.
This routine has worked for several years and is used to set a list of values into parameters:
Public Sub ApplyIDS()
Dim pdv As ParameterDiscreteValue
With _parameter.CurrentValues
.Clear()
Select Case _IDs.Count
Case 0
If ZeroEmptyParameter Then
Report.SetParameterValue(_parameter.ParameterFieldName, 0)
Else
.IsNoValue = True
End If
Case 1
If _parameter.ParameterType = CrystalDecisions.Shared.ParameterType.StoreProcedureParameter Then
Report.SetParameterValue(_parameter.ParameterFieldName, _IDs(0))
ElseIf _parameter.ParameterType = CrystalDecisions.Shared.ParameterType.ReportParameter Then
SetCrystalParam(Me.Report, _parameter.ParameterFieldName, _IDs(0))
End If
Case Else
For Each paramValue As Int32 In _IDs
pdv = .AddValue(paramValue)
Next
End Select
End With
End Sub
The Case Else is the one being executed. After this exits I can see that the parameter in question has a list of current values. The report in question uses the following code to check the parameter:
((({?MICID}=0) and hasvalue({?MICShareID}) and {vwMICSharesForRedemption.MSID}={?MICShareID})
or ({vwMICSharesForRedemption.MICID}={?MICID})
and ({vwMICSharesForRedemption.TransferCertificateRequired} = true
or {vwMICSharesForRedemption.RedemptionCertificateRequired} = true))
In this report the MICID is usually zero and a list of MICShareIDs is set by the above code. As of the most recent version, all of the reports which use this technique are now ignoring the list of values that have been set and are prompting for lists of values. What changed between v13 and v22?
I am a little desperate as I need to get a release out and I was going to upgrade all of the users to the most recent v22 runtime. I cannot do so if all of the reports are going to prompt for parameters.
Thanks, Neil
Request clarification before answering.
Don, I found a work-around, although I don't know why it works. Basically the 'else' code gets replaced with a new function, based on a routine that I think you had previously written and that I have adapted:
SetCrystalParamList(Of Integer)(Me.Report, _parameter.ParameterFieldName, _IDs)
The new function is this:
Friend Sub SetCrystalParamList(Of E)(rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument, parameterName As String, listOfValues As IEnumerable(Of E))
Dim ParCount As Integer = rpt.DataDefinition.ParameterFields.Count
Dim crDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue
For Each crParamField As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition In rpt.DataDefinition.ParameterFields
If crParamField.Name.ToLower() = parameterName.ToLower() OrElse "@" + crParamField.Name.ToLower() = parameterName.ToLower() Then
Try
Dim myparameterValues As New CrystalDecisions.Shared.ParameterValues()
'myparameterValues.IndexOf(crParamField.Name)
For Each value As E In listOfValues
crDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()
crDiscreteValue.Value = value
myparameterValues.Add(crDiscreteValue)
Next
crParamField.ApplyCurrentValues(myparameterValues)
Return
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
End If
Next
End Sub
This successfully sets the value list and prevents prompting. Why this works and parameter.AddValue() does not, I have no clue.
Thanks, Neil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
62 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.