Results 1 to 11 of 11

Thread: Passing a Variable as a Parameter Issue

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2011
    Posts
    31

    Passing a Variable as a Parameter Issue

    I'm developing a program in VS02 that displays and exports a CR11 report at a certain screen. It works fine when I hard code the report like this:
    vb.net Code:
    1. Dim cryRpt As New ReportDocument()
    2. Dim reportPath As String = "ReportPath\ReportFile.rpt"
    3. Dim testInt As Integer
    4. testInt = TextBox1.Text
    5.  
    6. cryRpt.Load(reportPath)
    7. cryRpt.SetParameterValue("InspKey", 123456)
    8. CrystalReportViewer1.ReportSource = cryRpt
    9. CrystalReportViewer1.Refresh()
    10.  
    11. Try
    12. Dim CrExportOptions As ExportOptions
    13. Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
    14. Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
    15. CrDiskFileDestinationOptions.DiskFileName = "OutputPath\123456.pdf"
    16. CrExportOptions = cryRpt.ExportOptions
    17.  
    18. With CrExportOptions
    19.     .ExportDestinationType = ExportDestinationType.DiskFile
    20.     .ExportFormatType = ExportFormatType.PortableDocFormat
    21.     .DestinationOptions = CrDiskFileDestinationOptions
    22.     .FormatOptions = CrFormatTypeOptions
    23. End With
    24.  
    25. cryRpt.Export()
    26.  
    27. Catch ex As Exception
    28.     MsgBox(ex.ToString)
    29. End Try

    But if I change the parameter to a variable as well as the name of the exported report it will show up with no data:
    vb.net Code:
    1. Dim cryRpt As New ReportDocument()
    2. Dim reportPath As String = "ReportPath\ReportFile.rpt"
    3. Dim testInt As Integer
    4. testInt = TextBox1.Text
    5.  
    6. cryRpt.Load(reportPath)
    7. cryRpt.SetParameterValue("InspKey", testInt)     'Changes here
    8. CrystalReportViewer1.ReportSource = cryRpt
    9. CrystalReportViewer1.Refresh()
    10.  
    11. Try
    12. Dim CrExportOptions As ExportOptions
    13. Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
    14. Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
    15. CrDiskFileDestinationOptions.DiskFileName = "OutputPath\" & testInt & ".pdf"     'Changes here
    16. CrExportOptions = cryRpt.ExportOptions
    17.  
    18. With CrExportOptions
    19.     .ExportDestinationType = ExportDestinationType.DiskFile
    20.     .ExportFormatType = ExportFormatType.PortableDocFormat
    21.     .DestinationOptions = CrDiskFileDestinationOptions
    22.     .FormatOptions = CrFormatTypeOptions
    23. End With
    24.  
    25. cryRpt.Export()
    26.  
    27. Catch ex As Exception
    28.     MsgBox(ex.ToString)
    29. End Try
    I know the report is still receiving the variable as I placed the parameter itself on the report for testing. When the report is run/exported the correct parameter shows up fine. I also have an OLE object on the report that references a dynamic picture file (signature of customer is obtained and created into a .jpg). THAT shows up fine as well and is based on the passed parameter of the report! Anyone have an idea as to why this works hard coded but not with a variable? It's the last part of a project that needs to be done but I'm being driven nuts trying to solve this last issue.
    Last edited by llDayo; Aug 31st, 2011 at 11:09 AM. Reason: Changed output path and added comments at targeted code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width