Exporting Report to PDF using VB

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
manmmadhokAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mlmccConnect With a Mentor Commented:
'
'   Set export options
'
    crRpt.ExportOptions.DestinationType = crEDTDiskFile
    crRpt.ExportOptions.DiskFileName = txtAttachmentFile
    crRpt.ExportOptions.FormatType = crEFTWordForWindows
    crRpt.Export False

mlmcc
0
 
mlmccCommented:
Can you export from the RDC viewer?

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

mlmcc
0
 
pdrauCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
manmmadhokAuthor Commented:
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
 
mlmccCommented:
Do you use the same connection method to view the report?  If not have you tried using that method for the export?

mlmcc
0
 
manmmadhokAuthor Commented:
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
 
mlmccCommented:
Let me find my exporting code.  I export using the RDC so the method of viewing and exporting are very similar.

mlmcc
0
 
manmmadhokAuthor Commented:
Hi there,

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

Many Thanks,
Manish
0
 
manmmadhokAuthor Commented:
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
 
mlmccCommented:
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
 
manmmadhokAuthor Commented:
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
 
mlmccCommented:
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
 
manmmadhokAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.