Solved

Exporting Crystal eports through VB6 Crystal OCX

Posted on 2002-05-16
14
1,295 Views
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?
0
Comment
Question by:zoobird
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
How are you doing the export?

If it is from VB please show the code.

mlmcc
0
 
LVL 1

Expert Comment

by:Brighton
Comment Utility
If you are using VB then try prior to your export.

DisplayProgressDialog = False
0
 

Author Comment

by:zoobird
Comment Utility
is DisplayProgressDialog a property of the Crystal Report object?
0
 
LVL 1

Expert Comment

by:Brighton
Comment Utility
Yes
 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)))
    Report.DiscardSavedData
   
    '
    ' 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
    Next
   
    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)))
          Else
             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))
        Form2.Show
    Else
   
        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
   
   
ErrorHandle:
   
    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)
     Do
           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

           Else

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

           End If

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

     Loop
     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)
     


0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
is DisplayProgressDialog a property of the Crystal Report object?

yes

CR1.DisplayProgressDialog = false

mlmcc
0
 

Author Comment

by:zoobird
Comment Utility
I don't have that option in my crystal report object.
0
 
LVL 1

Expert Comment

by:kzbera
Comment Utility
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"
CRPReport.Preview

        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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
DisplayProgressDialog
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.

mlmcc
0
 

Author Comment

by:zoobird
Comment Utility
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.

0
 

Author Comment

by:zoobird
Comment Utility
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.
0
 

Author Comment

by:zoobird
Comment Utility
kzbera,

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

Expert Comment

by:mlmcc
Comment Utility
Add the following line

Form1.CrystalReport1.Destination = crptToFile

replace
lReturnCode = Form1.CrystalReport1.PrintReport
 with

Form1.CrystalReport1.Action = 1

mlmcc
0
 

Author Comment

by:zoobird
Comment Utility
Unfortunately, I'm still being prompted whether to export all pages or specific pages. It only happens with exporting to RTF format.
0
 
LVL 100

Accepted Solution

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

Report.ExportOptions.RTFExportAllPages = True

http://support.crystaldecisions.com/library/kbase/articles/c2010169.asp

mlmcc


0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now