Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is awesome!...Things I have been trying to figure out for weeks, I got the answer in hours!..."

Geography

Where in the world do Tek-Tips members come from?

Print Crystal Report to Disk from VB.NETHelpful Member! 

johnhugh (TechnicalUser)
1 May 12 8:00
Hi, I'm very new to VB.NET and am in need for some help.
For 2 days I'm now trying to get my code to print a PDF from Crystal to PDF.

I'm trying to translate a VB6 program to VB.Net 2010.
This is the VB6 program. All it does is, take an existing report and print a pdf to disk.
The only reason I want to migrate it to VB.NET is because in VB6 I don't seem to be able to export Group Headers as PDF bookmarks.
If anyone know a way of exporting group headers as bookmarks I can save me the whole .net translation.

CODE

Dim crystal As CRAXDRT.Application
Dim report As CRAXDRT.report       
Set crystal = CreateObject("CrystalRuntime.Application.10")
Set report = crystal.OpenReport("c:\Balances.rpt")

report.EnableParameterPrompting = False
Set Parameters = report.ParameterFields
For cnt = 1 To Parameters.Count
  Set Parameters = Parameters.Item(cnt)
  If Parameters.Name = "{?Country}" Then
    Parameters.ClearCurrentValueAndRange
    Parameters.AddCurrentValue "10" 'Tanzania
  End If
Next

'report.ExportOptions.CreateBookmarksFromGroupTree = True
report.ExportOptions.DiskFileName = "c:\Balances.pdf"
report.ExportOptions.FormatType = crEFTPortableDocFormat
report.ExportOptions.DestinationType = crEDTDiskFile
report.ExportOptions.PDFExportAllPages = True
report.Export False

Set report = Nothing
Set crystal = Nothing

I've started in VB.Net already but can simply not get it to work.
I'm testing with CR XI R2 and Visual Studio 2010.

I start by creating a new Crystal Reports Application and choose the report I want to use. I figure this might not be necessary as I don't want anything to display, just run the .exe to print the pdf as an scheduled process later on.
I've removed the CrystalReportViewer and the CrystalReportDocument control from my form and just added a button to test it.

This is my code:

CODE

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Windows.Forms

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim crReport As ReportDocument
            Dim crPDFOptions As PdfFormatOptions

            Dim strFileName As String
            Dim reportPath As String = ""

            strFileName = "test"
            crReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument ' here it throws an exception

            crReport.Load("c:\Balances.rpt", OpenReportMethod.OpenReportByTempCopy)

            crPDFOptions = New PdfFormatOptions()
            crPDFOptions.CreateBookmarksFromGroupTree = True

            Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
            CrDiskFileDestinationOptions.DiskFileName = "C:\" & strFileName & ".pdf"
            With crReport.ExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
            crReport.Export()

            crReport = Nothing
            CrDiskFileDestinationOptions = Nothing
            CrFormatTypeOptions = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

The exception it throws at crReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument is the following.

"Retrieving the COM class factory for component with CLSID {4DB2E2BB-78E6-4AEA-BEFB-FDAAB610FD1B} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

I don't have any references to a COM class and don't hink I should have.
But this is about all I can read from that error.

Any help is really appreciated.

 
Helpful Member!  jebenson (TechnicalUser)
1 May 12 16:09
Is your PC a 64-bit machine?  If it is, try changing the Target CPU to x86:


Project menu -> <ProjectName> Properties

In the Properties window, click on "Compile" in the left pane.  In the right pane, click the "Advanced Compile Options" button.  In the "Advanced Compiler Settings" dialog, change the "Target CPU" dropdown to "x86".  Hit OK and run the application.

You might also try installing the Crystal Reports runtime files, which can be found through Google.

 

I used to rock and roll every night and party every day.  Then it was every other day.  Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys!  Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!  

johnhugh (TechnicalUser)
1 May 12 23:19
Setting the target CPU fixed it. Thank you so much!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close