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...
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....
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.
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....
Re: Crystal Report to PDF with Selection
Re: Crystal Report to PDF with Selection
Quote:
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)
Quote:
BUT I am gettig this error...."Subscript out of Range"
Collections are 1 based not 0 based like arrays.
Quote:
rep.FormulaFields.Add "{VillageName}",village_name
Should be something like
rep.FormulaFields.Add "DisplayVillageName","{VillageName} = '" & village_name & "'"
Re: Crystal Report to PDF with Selection
Thankx for ur reply..
Will give it a try.
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...
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.