Hi,
I have a crystal report that fails on a formula field but I cannot see why.
Here is my code:
The code throws an exception on the _report.Export() line.
The details of the exception are:
Here is the dataset:
If have hacked the field formula in the report to eliminate other problems to from this:
This gives me the same error, however:
Does not error, So some how the value in the dataset are not coming through.
This has had me stumped all this afternoon. In the code I originally set the datasource on my report after I added the parameters. I changed this as the parameters values got wiped.
Has anyone got any suggestions as to what I am doing wrong?
I really struggle with crystal
Thanks, Dave.
I have a crystal report that fails on a formula field but I cannot see why.
Here is my code:
Code:
Public Function CreateReportPDF(ByVal dsReport As DataSet, ByVal CrystalReportPath As String, _
ByVal reportSize As String, ByVal landScape As Boolean, _
ByVal dsParameters As DataSet, ByVal filePath As String, _
ByVal fileName As String) As Boolean
Try
Load report including report path etc.
_report.Load(CrystalReportPath, OpenReportMethod.OpenReportByTempCopy)
_report.SetDataSource(dsReport)
Deal with any report parameters.
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldLocation As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
Get the reports parameters collection.
crParameterFieldDefinitions = _report.DataDefinition.ParameterFields
For counter As Int32 = 0 To (dsParameters.Tables("ReportParameters").Rows.Count - 1)
crParameterFieldLocation = crParameterFieldDefinitions.Item(dsParameters.Tables("ReportParameters").Rows(counter).Item("Key").ToString)
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = dsParameters.Tables("ReportParameters").Rows(counter).Item("Value").ToString
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
Next
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
Set the destination path and file name.
CrDiskFileDestinationOptions.DiskFileName = "c:\Test.pdf"
Set export options.
CrExportOptions = _report.ExportOptions
With CrExportOptions
Set the destination to a disk file.
.ExportDestinationType = ExportDestinationType.DiskFile
Set the format to PDF
.ExportFormatType = ExportFormatType.PortableDocFormat
Set the destination options to DiskFileDestinationOptions object.
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
Export the report.
_report.Export()
Catch ex As Exception
Dim strEx As String = ex.ToString
End Try
End Function
The code throws an exception on the _report.Export() line.
The details of the exception are:
A string is required here.A string is required here.
Error in File C:\DOCUME~1\me\LOCALS~1\Temp\Snapshot {179546E4-7F1E-419C-944C-16C97E961CF0}.rpt:
Error in formula <fWeight>.
iif({Snapshot.snapshot}=1,"",cstr({Snapshot.weight},3))
Here is the dataset:
Code:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Snapshot>
<snapshot>1</snapshot>
<stage>Drawing Office</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>Planning</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>Released to Sub Fab</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>Sub Fabrication</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>Own Treatment</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>Treated</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>Loaded</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>In Packages</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>In Containers</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>At Site</stage>
<fcode />
<stcode />
<weight>28.604</weight>
</Snapshot>
<Snapshot>
<snapshot>1</snapshot>
<stage>Erected</stage>
<fcode />
<stcode />
<weight>0</weight>
</Snapshot>
</NewDataSet>
If have hacked the field formula in the report to eliminate other problems to from this:
To this:iif({Snapshot.snapshot}=1,"",cstr({Snapshot.weight},3))
iif({Snapshot.snapshot}=1,"Yep","Nope")
This gives me the same error, however:
iif(1=1,"Yep","Nope")
Does not error, So some how the value in the dataset are not coming through.
This has had me stumped all this afternoon. In the code I originally set the datasource on my report after I added the parameters. I changed this as the parameters values got wiped.
Has anyone got any suggestions as to what I am doing wrong?
I really struggle with crystal
Thanks, Dave.