Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exporting Report to PDF using VB

Posted on 2004-10-29
16
Medium Priority
?
671 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
Comment
Question by:manmmadhok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
16 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 12445245
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
ID: 12447874
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
ID: 12472710
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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
LVL 101

Expert Comment

by:mlmcc
ID: 12479699
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
ID: 12484583
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 101

Expert Comment

by:mlmcc
ID: 12489465
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
ID: 12556109
Hi there,

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

Many Thanks,
Manish
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 200 total points
ID: 12576987
'
'   Set export options
'
    crRpt.ExportOptions.DestinationType = crEDTDiskFile
    crRpt.ExportOptions.DiskFileName = txtAttachmentFile
    crRpt.ExportOptions.FormatType = crEFTWordForWindows
    crRpt.Export False

mlmcc
0
 

Author Comment

by:manmmadhok
ID: 12765202
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 101

Expert Comment

by:mlmcc
ID: 12770807
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
ID: 12784575
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 101

Expert Comment

by:mlmcc
ID: 12789283
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
ID: 12809551
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

598 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