Question exporting crystal report to PDF

cypress1976

Member
Joined
Aug 18, 2009
Messages
7
Programming Experience
3-5
I am trying to export only the current record in my app into a PDF. My current code (shown below) is exporting into Crystal Report and then into PDF format but it is exporting ALL records in the database.

This program is used for entering in Purchase Requests. Each record in the database is one purchase request. Once the record is inputted, a button is clicked and the conversion occurs and saves the PDF file.

How can I tell the program to just export the current record I am viewing in my program....not all records in the database.

This is VB.net 2005 with an Access database.

VB.NET:
Private Sub btnSubmitNewReq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmitNewReq.Click

cryRpt.Load("H:\programs\PR_Requests\PR_Requests\rptPRRequests.rpt")

        Try
            Dim CrExportOptions As ExportOptions
            Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
            CrDiskFileDestinationOptions.DiskFileName = "H:\PR_Request_" & lblRequestNum.Text & ".pdf"
            CrExportOptions = cryRpt.ExportOptions
            With CrExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
            cryRpt.Export()
        Catch ex As System.Exception
            MsgBox(ex.ToString)
        End Try
End Sub

Thanks for any help!!
Jason
 
I have partially solved this problem of mine by adding this line of code:

VB.NET:
cryRpt.RecordSelectionFormula = "{PRREQUESTS.ID} = " & lblRequestNum.Text

but now after I export one record and I move ahead to the next record, that second record's PDF file has only the crystal report format in it (it does not contain the data from the record).

To sum up:
I can export one record once using the above code snippet but when I try it for a second time on another record, I get a blank PDF file (only the crystal report formatting is in the PDF).

Here is all the code for what I am doing:
VB.NET:
Private Sub btnSubmitNewReq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmitNewReq.Click

        cryRpt.Load("H:\programs\PR_Requests\PR_Requests\rptPRRequests.rpt")

        Try

            cryRpt.RecordSelectionFormula = "{PRREQUESTS.ID} = " & lblRequestNum.Text

            Dim CrExportOptions As ExportOptions
            Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
            CrDiskFileDestinationOptions.DiskFileName = "H:\PR_Request_" & lblRequestNum.Text & ".pdf"
            CrExportOptions = cryRpt.ExportOptions
            With CrExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
            cryRpt.Export()
        Catch ex As System.Exception
            MsgBox(ex.ToString)
        End Try
End Sub

Thanks,
jason
 

Latest posts

Back
Top