Solved

Exporting Report to PDF using VB

Posted on 2004-10-29
651 Views
Last Modified: 2008-01-09
Hi there,
I am using crystal report 8.5 and VB6 with Oracle 8i
I created a report using 'Oracle Server' Connection method. Oracle Ref Cursors are used to return the data into the report instead of normal OLEDB connection method.
The report runs fine when previewed from crystal. The report also runs fine when I use RDC in VB6 to view the report.

But when I try to export the report into PDF from VB6 [No RDC] it returns
an error 'Server has not yet been opened.'

Attached below is the code:

Public Sub SendReportEmail_Fax(lDespHdrID As Long, strPassSendTo As String, _
strShippingRefNo As String, strCustRef As String, iOrgID As Integer, Optional strMailToName As String = "")

Dim strEmailtxt As String, strErrMsg As String
Dim crxApp As CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report
Dim crxParamld As CRAXDRT.ParameterFieldDefinition
Dim crxTable As CRAXDRT.DatabaseTable

Set crxApp = New CRAXDRT.Application
Set crxRpt = crxApp.OpenReport(gRptPath & "reportname.rpt")
Set crxTable = crxRpt.Database.Tables.Item(1)

crxTable.SetLogOnInfo <TNS Service Name>, <TNS Service Name>, <Oracle User Name>, <Oracle Password>

Set crxParamld = crxRpt.ParameterFields(1)
crxParamld.AddCurrentValue ("hi")

Set crxParamld = crxRpt.ParameterFields(2)
crxParamld.AddCurrentValue (10000120)

crxRpt.DisplayProgressDialog = False
crxRpt.ExportOptions.FormatType = crEFTPortableDocFormat
crxRpt.ExportOptions.PDFExportAllPages = True
crxRpt.ExportOptions.UseReportDateFormat = True
crxRpt.ExportOptions.UseReportNumberFormat = True
crxRpt.DisplayProgressDialog = True
crxRpt.ExportOptions.DestinationType = crEDTEMailMAPI
crxRpt.ExportOptions.ExchangeProfile = "Manish"
crxRpt.ExportOptions.MailSubject = "Email Report"

strEmailtxt = "hi there " & Chr(13)
strEmailtxt = strEmailtxt & "Please sign and return the attached document as confirmation of receipt of supplies to "
strEmailtxt = strEmailtxt & Chr(13) & Chr(13) & Chr(13) & "Kind Regards"

crxRpt.ExportOptions.MailMessage = strEmailtxt

crxRpt.ExportOptions.MailToList = "manmmadhok@yahoo.com"
crxRpt.Export (False)

Set crxTable = Nothing
Set crxParamld = Nothing
Set crxRpt = Nothing
Set crxApp = Nothing

End Sub

Please help me on this...!
I would really appreciate any kind help on this.


Many Thanks
Manish
0
Question by:manmmadhok
    13 Comments
     
    LVL 100

    Expert Comment

    by:mlmcc
    Can you export from the RDC viewer?

    Is this the same basic code you use to setup the report for viewing?

    mlmcc
    0
     
    LVL 2

    Expert Comment

    by:pdrau
    This is VB.NET code, but it may help

    Dim exportFilePath As String = strDir & "\" & strReportTitle & ".pdf"

            'Set the options for saving the exported file to disk
            crDiskFileDestinationOptions = New DiskFileDestinationOptions
            crDiskFileDestinationOptions.DiskFileName = exportFilePath

            'Set the exporting information
            crExportOptions = crReportDocument.ExportOptions
            With crExportOptions
                .DestinationOptions = crDiskFileDestinationOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
            End With

            Try
                'Export the report
                crReportDocument.Export()
           Catch ex As Exception


    Hope this helps.
    0
     

    Author Comment

    by:manmmadhok
    Thanks a lot for the response.

    I am a Report Designer Component for viewing the report and its a different code.
    For export I have use this code. I noticed that when I do the connection test using 'crxTable.TestConnectivity' it returns False instead of True.

    Thanks pdrau for your response. I tried this with .net also but the same result..!

    Guys, I am really stuck over here...! Please help.

    Many thanks in advance.
    Manish
    0
     
    LVL 100

    Expert Comment

    by:mlmcc
    Do you use the same connection method to view the report?  If not have you tried using that method for the export?

    mlmcc
    0
     

    Author Comment

    by:manmmadhok
    Hi there,

    Thanks for the reply.

    I am adding crystal report control component on a VB form and than making a connection to it.
    The connection method for viewing the report is:
    <crystal report control name>.Connect "DSN = " & Service & ";PWD = " & Passwd & ";UID = " & UName & ";Extended Properties='PLSQLRSet=1'"

    now, may be I am missing something over here or may be I am not aware the functionality of exporting report via crystal report control name. But as far as I know we can't export the report using this method.

    The connection method for exporting the report is already specified in the question posted above.

    What I can't understand is that I can export the same report from crystal, view the same report using crystal report control component but I can't export it.

    Please let me know in case you require more information.

    Many Thanks,
    Manish
    0
     
    LVL 100

    Expert Comment

    by:mlmcc
    Let me find my exporting code.  I export using the RDC so the method of viewing and exporting are very similar.

    mlmcc
    0
     

    Author Comment

    by:manmmadhok
    Hi there,

    I will really appreciate if you could help me on this.
    Thanks in advance.

    Many Thanks,
    Manish
    0
     
    LVL 100

    Accepted Solution

    by:
    '
    '   Set export options
    '
        crRpt.ExportOptions.DestinationType = crEDTDiskFile
        crRpt.ExportOptions.DiskFileName = txtAttachmentFile
        crRpt.ExportOptions.FormatType = crEFTWordForWindows
        crRpt.Export False

    mlmcc
    0
     

    Author Comment

    by:manmmadhok
    Hi,
    My apologies for not posting any comment on this post.
    I was trying different things and thought I will post the solution once I get it - which I am still not able to get it.

    The report will be exported in the Word format according to the code specified and not in the PDF format, which actually I require.

    Please let me know if we have any solution to this problem as I am really stuck and have to implement the report by using different method which is not an ideal solution.

    Many Thanks
    Manish
    0
     
    LVL 100

    Expert Comment

    by:mlmcc
    Change this line
    crRpt.ExportOptions.FormatType = crEFTWordForWindows
    to
    crRpt.ExportOptions.FormatType = crEFTPDFFormat

    The crEFTPDFFormat may still be wrong but it should be in the dropdown in the VB editor.

    mlmcc
    0
     

    Author Comment

    by:manmmadhok
    Thanks a lot for your reply mlmcc.

    But if you read the question I am using the same method what you suggested.

    I am using crystal report control Component [You select this from the Toolbox in VB and this is not a CRViewer control].

    now with this component I can not export the report in the format desired.
    I am using the following code for that

            cryRpt1ShipRqst.Destination = crptMapi
            cryRpt1ShipRqst.EMailToList = "<email-id>"
            cryRpt1ShipRqst.EMailSubject = "TEST "
            cryRpt1ShipRqst.ACTION = 1

    this exports the report with the extension <Reportname>.rec Which I can't get it opened and also i want the report to be exported in PDF format as that is the part of the requirement.

    thanks anyway for the help as this call has been closed forcefully without getting any solution.

    Many Thanks to the Administrator for closing the call without getting the solution to the problem...

    Many Thanks,
    Manish

    0
     
    LVL 100

    Expert Comment

    by:mlmcc
    As I tried to tell you in the earlier posts, you need to specufy the format for the attachment.

            cryRpt1ShipRqst.Destination = crptMapi
            cryRpt1ShipRqst.EMailToList = "<email-id>"
            cryRpt1ShipRqst.EMailSubject = "TEST "
    cryRpt1ShipRqst.PrintFileType = crptPDF
            cryRpt1ShipRqst.ACTION = 1

    Also in the original question you were using the RDC now you have changed the method and are using the OCX which may not be able to export to PDF.


    mlmcc
    0
     

    Author Comment

    by:manmmadhok
    Hi mlmcc,

    Thanks a lot for your response. It’s really appreciated

    I may have to find some other solution to the problem.

    Thanks once again.

    Best Regards
    Manish
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
    Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now