I am trying to export 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.

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

Recommended Answers

All 6 Replies

Use RecordSelectionFoumula,

ReportsourceObject.RecordSelectionforumal="{tableName.colName}=1"

Thanks for the reply....I appreciate it. Can you advise where I hsould use that piece of code?

Thanks again,
Jason

Questions regarding your code snippet....

I assume "ReportsourceObject" is my crystal report "cryRpt"...is this correct?

Can you provide more detail as to the last part of the code "{tableName.colName}=1"? I do not understand what you are doing there.

Thanks again for the help!!
jason

I was able to get your code snippet to work but the exported PDF is not showing any record in it. It is only showing one blank crystal report sheet.

Here is the code with your code snippet in it....maybe I am putting it in the wrong place. Any advise?

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
            cryRpt.RecordSelectionFormula = "{PRREQUESTS.ID} = 1"
            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

Got it figured out. :) Thanks for the guidance. I appreciate it.

For anyone else interested, here is the code that I used:

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

Jason

i have a error in this line

// CrDiskFileDestinationOptions.DiskFileName = "C:\Purhcaseregister";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.