Exporting Crystal eports through VB6 Crystal OCX

Posted on 2002-05-16
Last Modified: 2007-11-27
I want to export a Crystal 8.5 report to RTF format. Whenever I do this, I am prompted as to whether to export all the pages or to specify specific pages. Is there any way to get rid of this and default the option to All Pages?
Question by:zoobird
  • 6
  • 5
  • 2
  • +1
LVL 100

Expert Comment

ID: 7014196
How are you doing the export?

If it is from VB please show the code.


Expert Comment

ID: 7014217
If you are using VB then try prior to your export.

DisplayProgressDialog = False

Author Comment

ID: 7014585
is DisplayProgressDialog a property of the Crystal Report object?
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Expert Comment

ID: 7014656
 Here is a little VB program on how I use it.

Dim crxApplication As New CRAXDRT.Application

Private Report As CRAXDRT.Report

Private Sub Form_Load()

    ' This program expects at lest 3 parameters to be passed to it
    ' and the program first parses the command line into a ParameterArray
    ' ParameterArray(1)   = Report to run
    ' ParameterArray(2)   = Output destination
    ' ParameterArray(3)   = What format is the output saved as
    ' ParameterArray(4+N) = Parameters that are passed to the crystal
    '                       report in the same order they are listed
    '                       in the report.
    ' The program them sets any parameters the are passed in to it and places
    ' these values in the parameters that are in the report.

    On Error GoTo ErrorHandle
    Dim linenbr As Integer
    Dim ParameterArray() As String
    Dim OutFile          As String      'ParameterArray(2)
    Dim OutputFormat     As Integer     '0 = No Format
                                        '1 = Crystal Report Format
                                        '8 = Text
                                        '31 = PDF
    Dim RC As Integer
    Dim Pcnt As Integer
    ' Fill the array with the command line passed in
    ' using the comma as a deliminator between fields.
    RC = FillArray(Command, ",", ParameterArray())
    Set crxApplication = New CRAXDRT.Application
    Dim crxParameterField As CRAXDRT.ParameterFieldDefinition
    Dim crxparameterFields As CRAXDRT.ParameterFieldDefinitions
    ' The first parameter passed in is the name of the
    ' report to run
    Set Report = crxApplication.OpenReport(Trim(ParameterArray(1)))
    ' The second parameter is the location where the
    ' the output file is to go
    OutFile = Trim(ParameterArray(2))
    Pcnt = Report.ParameterFields.Count
    If Pcnt > 0 Then
        Set crxParameterField = Report.ParameterFields.Item(1)
    End If
    ' Log on to the database
    For i = 1 To Report.Database.Tables.Count
        Report.Database.Tables(i).SetLogOnInfo "", "", "<<Use Integrated Security>>", ""
    Next i
    If Pcnt > 0 Then
        crxParameterField.EnableMultipleValues = True
        Call crxParameterField.ClearCurrentValueAndRange
    End If

    ' Read each parameter from the report and populate
    ' them in the same order they are read in from
    ' the command line.
    Dim crnull As Variant
    For Each crxParameterField In Report.ParameterFields
        crxParameterField.AddCurrentValue crnull
    Pcnt = Report.ParameterFields.Count
    If Pcnt > 0 Then
        For x = 1 To Pcnt
          If ParameterArray(x + 3) = "" Then
             Report.ParameterFields(x).AddCurrentValue crnull
          ElseIf Report.ParameterFields(x).ValueType = crNumberField Then
             Report.ParameterFields(x).AddCurrentValue CDbl(Trim(ParameterArray(x + 3)))
             Report.ParameterFields(x).AddCurrentValue CStr(Trim(ParameterArray(x + 3)))
          End If
        Next x
    End If
    Select Case Trim(CInt(ParameterArray(3)))
     Case Is = 0
      OutputFormat = 0  ' No Format
     Case Is = 1
      OutputFormat = 1  ' Crystal Report Format
     Case Is = 8
      OutputFormat = 8  ' Text
     Case Is = 31
      OutputFormat = 31 ' crEFTPortableDocFormat (PDF)
    End Select
    If OutputFormat = 0 Then
        RptName.Caption = Trim(ParameterArray(1))
        Report.DisplayProgressDialog = False
        Report.ExportOptions.DestinationType = crEDTDiskFile
        Report.ExportOptions.FormatType = OutputFormat
        Report.ExportOptions.DiskFileName = OutFile
        Report.Export False
    End If

    Err.Number = 0
    Unload ExecCR
    Exit Sub
    Label1.Caption = linenbr
    Label2.Caption = Err.Number
    Label3.Caption = Err.Description
    Debug.Print Err.Number
    Err.Number = 1
    Unload ExecCR
End Sub

Function FillArray(CommandLineIn As String, Delimiter As String, aValues() As String) As Integer

     Dim ArrayCount As Integer
     Dim CurrentPosInArray As Integer
     Dim LenghtOfVariable As Integer
     Dim StringLength As Integer

     ArrayCount = 1
     CurrentPosInArray = 1
     LenghtOfVariable = 1

     StringLength = Len(CommandLineIn)
           ReDim Preserve aValues(1 To ArrayCount) As String

           StringLength = (InStr(CurrentPosInArray, CommandLineIn, Delimiter) - CurrentPosInArray)

           If StringLength < 0 Then

                 aValues(ArrayCount) = Right$(CommandLineIn, (Len(CommandLineIn) - (LenghtOfVariable - 1)))

                 Exit Do


                  aValues(ArrayCount) = Mid$(CommandLineIn, CurrentPosInArray, StringLength)

           End If

           LenghtOfVariable = LenghtOfVariable + (Len(aValues(ArrayCount)) + Len(Delimiter))
           CurrentPosInArray = LenghtOfVariable
           ArrayCount = ArrayCount + 1

     If ArrayCount = 2 Then
        ArrayCount = 3
        ReDim Preserve aValues(1 To ArrayCount) As String
        aValues(3) = 8
     End If

     FillArray = UBound(aValues)

End Function

You would need to add to the case statement the condition to look for RTF output if you wanted RichText output.

     Case Is = 4
      OutputFormat = 4 ' crEFTRichText (RTF)

LVL 100

Expert Comment

ID: 7016341
is DisplayProgressDialog a property of the Crystal Report object?


CR1.DisplayProgressDialog = false


Author Comment

ID: 7017115
I don't have that option in my crystal report object.

Expert Comment

ID: 7018055
Hi I used similar thing for exporting to pdf format where it exported all the report.
here is the code..
try similarly to export to RTF
let me know whether it worked or not

Private Sub Command6_Click()
Dim CRPApplication As CRPEAuto.Application
Dim CRPReport As
Dim db As CRPEAuto.Database
Dim dbT As CRPEAuto.DatabaseTables
Dim i As Integer

Set CRPApplication = CreateObject("Crystal.CRPE.Application")

 Set CRPReport = CRPApplication.OpenReport(app.Path & "\Magic Page.rpt")
'CRPApplication.LogOnServer "c:\winnt\system32\crpe32.dll", "XXX", "xxx", "yyy", "zzz"

Set CRPParameterFieldDefs = CRPReport.ParameterFields

For i = 1 To CRPParameterFieldDefs.Count

     Set CRPParameterFieldDef = CRPParameterFieldDefs.Item(i)
     'MsgBox CRPParameterFieldDef.Name

Next i

Set db = CRPReport.Database
Set dbT = db.Tables
 dbT.Item(1).SetLogOnInfo "XXX", "xxx", "yyy", "zzz"

        Dim strFileName, str As String
        Dim pos As Integer
        pos = InStr(1, (app.Path & "\Magic Page.rpt"), ".", vbTextCompare)
        str = Mid(app.Path & "\Magic Page.rpt", 1, pos - 1)
        strFileName = str & ".pdf"
'        CRPReport.ExportOptions.Reset
'        CRPReport.ExportOptions.DestinationType crEDTDiskFile
'        CRPReport.ExportOptions.FormatType crEFTPortableDocFormat
'        CRPReport.ExportOptions.DiskFileName strFileName ' save as
'        CRPReport.ExportOptions.PDFExportAllPages True
'         CRPReport.Export False ' overwrite and skip dialog box
'        MsgBox "exported"
End Sub
LVL 100

Expert Comment

ID: 7018277
I don't have that option in my crystal report object

There are several methods (ActiveX, RDC, OCX, Report Engine, Automation Engine)  Each has its own set of properties.  To help solve your problem we need to see the code you are using, the declaraion of the CR objects, and the CR references you are using.


Author Comment

ID: 7028765
Form1.CrystalReport1.PrintFileType = crptRTF
Form1.CrystalReport1.PrintFileName = "C:\report.rtf"

Form1.CrystalReport1.ReportFileName = "C:\report.rpt"
Form1.CrystalReport1.Connect = "DSN=reportdsn"
Form1.CrystalReport1.DialogParentHandle = False

lReturnCode = Form1.CrystalReport1.PrintReport

Unfortunately, when I do Form1.CrystalReport1.DisplayProgressDialog, I get an error because it doesn't seem to be a property of the CrystalReport1 object.


Author Comment

ID: 7028780
I found a similar property called ProgressDialog. However, that isn't my problem. My problem is when exporting the report to RTF format, it prompts for whether to print All pages or specific pages. I really don't care about the progress dialog box because it automatically closes. I don't want any user interaction with the program I'm writing.

I will increase points if necessary.

Author Comment

ID: 7030104

Do I need to make a reference to the CRPEAuto.Application? Which component should I reference to make it avaialble in my project?
LVL 100

Expert Comment

ID: 7030940
Add the following line

Form1.CrystalReport1.Destination = crptToFile

lReturnCode = Form1.CrystalReport1.PrintReport

Form1.CrystalReport1.Action = 1


Author Comment

ID: 7031110
Unfortunately, I'm still being prompted whether to export all pages or specific pages. It only happens with exporting to RTF format.
LVL 100

Accepted Solution

mlmcc earned 75 total points
ID: 7031136
Try this (it is for the RDC but i wouldn't be surprised if the ActiveX control had comething similar)

Report.ExportOptions.RTFExportAllPages = True



Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 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