Exporting Crystal eports through VB6 Crystal OCX

Posted on 2002-05-16
Medium Priority
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 101

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?
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.


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 101

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 CRPEAuto.report
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 101

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 101

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 101

Accepted Solution

mlmcc earned 225 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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