Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
|
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2003, 03:00 PM
Registered User
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Export existing reports to pdf

Hi,
I created many monthend reports using Crystal Report8.0. I try to export and print them automatically. So I write code in VB6.0.
Here is the code I tried:

Private Sub Form_Load()
Dim crxApp As New CRAXDRT.Application
Dim crxRpt As New CRAXDRT.Report
Set crxRpt = crxApp.OpenReport("c:\RptBusiness.rpt")
With crxRpt.ExportOptions
.FormatType = CRExportFormatType.crEFTPortableDocFormat
.DestinationType = CRExportDestinationType.crEDTDiskFile
.DiskFileName = "c:\RptExport1.pdf"
End With
crxRpt.Export (False)
Set crxApp = Nothing: Set crxRpt = Nothing
End Sub

This code run successfully with the report saved with data. Should the report doesn't saved with data. Err ocured "Run-time error
Server has not yet been opened".
Could someone give me a solution?
Thanks in advance.

:):):)
Happy Christmas!!!
Amy
 
Old October 19th, 2004, 11:27 AM
Authorized User
 
Join Date: Oct 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've used this and it is working for me. I'm using VB.NET, so I'm not certain how to make it fit your environment.

    Sub ExportReport()
        ' This subroutine uses a case statement to determine the selected export format from the dropdownlist
        ' menu and then sets the appropriate export options for the selected export format. The report is
        ' exported to a subdirectory called "C:\ExportFile\".

        ' ********************************
        'Check to see if the application directory has a subdirectory called "C:\ExportFile\".
        'If not, create the directory since exported files will be placed here.
        'This uses the Directory class of the System.IO namespace.
        Dim ExportPath As String
        ExportPath = "C:\ExportFile\"
        If Directory.Exists(ExportPath) = False Then
            Directory.CreateDirectory("C:\ExportFile")
        End If

        ' ********************************
        'Set the time for the file name
        Dim DateTimeNow As DateTime
        Dim Yr As Int16
        Dim Yr2 As String
        Dim Mth As Int16
        Dim mth2 As String
        Dim Dy As Int16
        Dim dy2 As String
        Dim Hr As Int16
        Dim hr2 As String
        Dim Mn As Int16
        Dim mn2 As String
        Dim strDateTimeNow As String

        DateTimeNow = Now()
        Yr = Year(DateTimeNow)
        Yr2 = Yr.ToString
        Mth = Month(DateTimeNow)
        If Mth <= 9 Then
            mth2 = "0" + Mth.ToString
        Else
            mth2 = Mth.ToString
        End If
        Dy = Day(DateTimeNow)
        If Dy <= 9 Then
            dy2 = "0" + Dy.ToString
        Else
            dy2 = Dy.ToString
        End If
        Hr = Hour(DateTimeNow)
        If Hr <= 9 Then
            hr2 = "0" + Hr.ToString
        Else
            hr2 = Hr.ToString
        End If
        Mn = Minute(DateTimeNow)
        If Mn <= 9 Then
            mn2 = "0" + Mn.ToString
        Else
            mn2 = Mn.ToString
        End If
        strDateTimeNow = Yr2 + mth2 + dy2 + hr2 + mn2

        ' ********************************
'IF you have logons, use this next section of code
        ' First we must create a new instance of the diskfiledestinationoptions class and
        ' set variable called crExportOptions to the exportoptions class of the reportdocument.
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table
        Dim TableCounter
        Dim crReportDocument As New ReportDocument

        'I had previously defined my file name to be exported in the variable
        'ReportFullFileName
        crReportDocument.Load(ReportFullFileName)

        'Set the ConnectionInfo properties for logging on to the Database

        'If you are using ODBC, this should be the DSN name NOT the physical server name. If
        'you are NOT using ODBC, this should be the physical server name

        With crConnectionInfo
            .ServerName = "Server"

            'If you are connecting to Oracle there is no DatabaseName. Use an empty string.
            'For example, .DatabaseName = ""

            .DatabaseName = ""
          'I had previously captured the UserID and Password and passed them to
          'variables strUID and strPWD.
            .UserID = strUID
            .Password = strPWD
        End With

        'This code works for both user tables and stored procedures. Set the CrTables to the Tables collection
        'of the report

        CrTables = crReportDocument.Database.Tables

        'Loop through each table in the report and apply the LogonInfo information

        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)

        Next

        crDiskFileDestinationOptions = New DiskFileDestinationOptions
        crExportOptions = crReportDocument.ExportOptions

'Though not used in this sample, there are options that can be specified for various format types.
        'When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the
        'first page, last page or page range to be exported.
        'When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as
        'the column width etc.

'Export to PDF


                'append a filename to the export path and set this file as the filename property for
                'the DestinationOptions class
                crDiskFileDestinationOptions.DiskFileName = ExportPath + ReportName + strDateTimeNow + ".pdf"

                'set the required report ExportOptions properties
                With crExportOptions
                    .DestinationOptions = crDiskFileDestinationOptions
                    .ExportDestinationType = ExportDestinationType.DiskFile
                    .ExportFormatType = ExportFormatType.PortableDocFormat
                End With
        Try
            ' Export the report
            crReportDocument.Export()
        Catch err As Exception
            Response.Write("<BR>")
            Response.Write(err.Message.ToString)
        End Try

    End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to existing excel file with headings Neal Access VBA 0 February 27th, 2008 03:31 PM
export to pdf nilsan ASP.NET 1.0 and 1.1 Professional 0 February 21st, 2007 06:24 AM
Export in PDF Format MER78 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 October 9th, 2004 11:43 AM
Export to .pdf bgottschall Crystal Reports 1 July 21st, 2004 06:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.