Results 1 to 9 of 9

Thread: Crystal Report to PDF with Selection

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    135

    Crystal Report to PDF with Selection

    Hello,

    I want to export data directly from Crystal Report to PDF. But I want to export only the selected records. For this i am using following code
    Code:
    Dim appl As New CRAXDDRT.Application
    Dim rep As CRAXDDRT.Report
    
    Set rep = appl.OpenReport(App.Path & "\Reports\pro_8_Eng.rpt", 1)
    rep.RecordSelectionFormula = "{Pro8.VillageNo} = " & cmbVillage.ItemData(cmbVillage.ListIndex)
    rep.ExportOptions.DiskFileName = App.Path & "\Reports\pdf_report.pdf"
    rep.ExportOptions.DestinationType = crEDTDiskFile
    rep.ExportOptions.FormatType = crEFTPortableDocFormat
    rep.Export False
    But I am getting the error as "Server Not Open"

    If I comment the RecordSelectionFormula line then it dosen't give any error but it generates the PDF for all the rows in the Data.

    I am using CR 8.5

    Thanx...

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    135

    Re: Crystal Report to PDF with Selection

    When I add the RecordSelectionFormula code then I am getting error as "Server Has not yet been Opened."

    Also If i try to add the following line in the above code :

    rep.FormulaFields.(0) = "VillageName='" & village_name & "'"

    then i am getting the error as :

    "Subscrpit Out of Range" error

    i have only one formula field in my report.

    Any help ..... plz....

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Crystal Report to PDF with Selection

    The only reason I can think of as to why this occurs is that the Save Data with Report option was selected. This means when there is no RecordSelection formula, the report does not need to connect to the database but once you add the formula it is trying to refresh the data.

    Try this to see if the above is the cause.

    Comment out the RecordSelectionFormula
    After the OpenReport statement add
    Rep.DiscardSavedChanges (not sure if that is the exact name of the method name)

    If you get the same error then you need to ensure a login has been set for all databases used by the report.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    135

    Re: Crystal Report to PDF with Selection

    Thanks for ur reply brucevde

    Since my database is password protected, it gives me that error. If I remove the password from the database then RecordSelectionFormula works fine.

    Also I am using FormulaFields in the report...
    Code:
    rep.FormulaFields(0)="VillageName='" & village_name & "'"
    BUT I am gettig this error...."Subscript out of Range"

    Any ideas as to why this error is comming.

    I tried writing it as
    Code:
    rep.FormulaFields.Add "{VillageName}",village_name
    but of no help. It dose not give me an error, but does not show the output on the report.

    pls reply....

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    135

    Re: Crystal Report to PDF with Selection

    Any help.....pls

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Crystal Report to PDF with Selection

    Since my database is password protected, it gives me that error. If I remove the password from the database then RecordSelectionFormula works fine.
    Why don't you get this error when there is no RecordSelectionFormula and the database is password protected (hint see above post)

    BUT I am gettig this error...."Subscript out of Range"
    Collections are 1 based not 0 based like arrays.

    rep.FormulaFields.Add "{VillageName}",village_name
    Should be something like
    rep.FormulaFields.Add "DisplayVillageName","{VillageName} = '" & village_name & "'"

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    135

    Re: Crystal Report to PDF with Selection

    Thankx for ur reply..

    Will give it a try.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    135

    Re: Crystal Report to PDF with Selection

    I tried this code...

    Code:
    Dim appl As New CRAXDDRT.Application
    Dim rep As CRAXDDRT.Report
    
    Set rep = appl.OpenReport(App.Path & "\Reports\pro_8_Eng.rpt", 1)
    
    rep.DiscardSavedData
    rep.RecordSelectionFormula = "{Pro8.VillagePanchayatNo} = " & cmbVillagePanchayat.ItemData(cmbVillagePanchayat.ListIndex)
    rep.FormulaFields.Add "DisplayVillageName", "{VillageName}='" & village_name & "'"
    rep.FormulaFields(1) = "{VillageName}='" & village_name & "'"
    
    rep.ExportOptions.DiskFileName = App.Path & "\Reports\pdf_report.pdf"
    rep.ExportOptions.DestinationType = crEDTDiskFile
    rep.ExportOptions.FormatType = crEFTPortableDocFormat
    rep.Export False

    but this still gives me an error on rep.FormulaFields(1) line as
    "Object dosen't support this property or method"

    If this line is commented then there is no error but report dosent show the value of FormulaField.

    Any guess why it is not working...

  9. #9
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Crystal Report to PDF with Selection

    There is no default property for a FormulaFieldDefinition object, so you have to be specific. Try

    rep.FormulaFields(1).Text = "{VillageName}='" & village_name & "'"

    What exactly is this formula suppose to do? It looks like it belongs in the RecordSelectionFormula. ie

    Where {VillageName} = 'XXXXX'

    That formula is useless anywhere else.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width