Export Crystal Report to PDF Programatically
Hi Friends,
I have a crystal report viewer and a button on a form.
I want that when the button is clicked the crystal report must automatically get exported to a pre-defined location as a pdf file.
I mean it should not ask for the location and the file format.
Hope I am able to convey my requirement.
Regards,
Vaibhav
Re: Export Crystal Report to PDF Programatically
You don't need the viewer, just reference the cr craxdrt library
Code:
Public CRApplication As New CRAXDRT.Application
Public CRReport As New CRAXDRT.Report
.
.
.
Set CRReport = CRApplication.OpenReport(App.Path & "\xxxx.rpt", 1)
CRReport.ExportOptions.FormatType = crEFTPortableDocFormat
CRReport.ExportOptions.DestinationType = crEDTDiskFile
CRReport.ExportOptions.DiskFileName = App.Path & "\xxxx.pdf"
CRReport.Export False
Re: Export Crystal Report to PDF Programatically
hi jggtz
Can you help me with my problem. its the same with that you instructed in this thread. heres the code
Private Sub cmdView_Click(Index As Integer)
Select Case Index
Case 0
If Me.optRR(0).Value = True Then irisreports (16)
If Me.optRR(1).Value = True Then irisreports (17)
If Me.optRR(2).Value = True Then irisreports (18)
If Me.optRR(3).Value = True Then irisreports (19)
If Me.optRR(4).Value = True Then irisreports (20)
If Me.optRR(5).Value = True Then irisreports (21)
If Me.optRR(6).Value = True Then irisreports (22)
If Me.optTransfer(0).Value = True Then irisreports (23)
If Me.optTransfer(1).Value = True Then irisreports (24)
If Me.optTransfer(2).Value = True Then irisreports (25)
If Me.optTransfer(3).Value = True Then irisreports (26)
If Me.optTransfer(4).Value = True Then irisreports (27)
If Me.optTransfer(5).Value = True Then irisreports (28)
If Me.optTransfer(6).Value = True Then irisreports (29)
Case 1
If Me.optEndingInv(0).Value = True Then irisreports (12)
If Me.optEndingInv(1).Value = True Then irisreports (13)
If Me.optEndingInv(2).Value = True Then irisreports (14)
If Me.optEndingInv(3).Value = True Then irisreports (15)
If Me.optEndingInv(4).Value = True Then irisreports (33)
Case 2
If Me.optCGS.Value = True Then
generateAverageCost
irisreports (30)
End If
If Me.optSalesSummary(0).Value = True Then irisreports (31)
If Me.optSalesSummary(1).Value = True Then irisreports (32)
'mat 08082006
If Me.optReportToGenerate(6).Value = True Then irisreports (46)
If Me.optReportToGenerate(0).Value = True Then irisreports (35) 'product breakdown
If Me.optReportToGenerate(1).Value = True Then irisreports (36) 'daily sales report net
If Me.optReportToGenerate(2).Value = True Then irisreports (40) 'daily sales report gross
If Me.optReportToGenerate(3).Value = True Then irisreports (37) 'tender department
If Me.optReportToGenerate(4).Value = True Then irisreports (38) 'sales register
If Me.optReportToGenerate(5).Value = True Then irisreports (39) 'gross profit
If Me.optSalesReceiptsWithTender.Value = True Then irisreports (60)
If Me.optSalesReceiptNumbers.Value = True Then irisreports (61)
If Me.optVATSales.Value = True Then irisreports (63)
Case 3
If Me.optJournal.Value = True Then irisreports (34)
Case 4
If Me.OptInventoryAdjustment.Value = True Then irisreports (62)
End Select
End Sub
hope you can help me with this one. thanks in advance.
Re: Export Crystal Report to PDF Programatically
Ok
That's the code where you select the report
Now post the code that's in the "insreports" procedure
Re: Export Crystal Report to PDF Programatically
Public Sub generateReport(ByVal vSqlstring As String)
Dim rstTemp As New ADODB.Recordset
On Error GoTo errSub
Me.MousePointer = vbHourglass
With rstTemp
If .State = adStateOpen Then .Close
.CursorLocation = adUseClient
DoEvents
.Open vSqlstring, cn(1), 3, 3
If .RecordCount > 0 Then
End If
frmDispReport.lblRecordTotal.Caption = "Total number of records : " & .RecordCount
End With
Set frmDispReport.dtgReport.DataSource = rstTemp
Set rstTemp = Nothing
Me.MousePointer = vbDefault
Exit Sub
errSub:
MsgBox Err.Description & " generatereport"
ErrorHandler Err.Number, Err.Description, "generatereport-inventory transactions"
Resume Next
End Sub
Re: Export Crystal Report to PDF Programatically
Hope i got it right.. i dont know what to upload sir. but this is the procedure to generate the reports. Cheers!
Re: Export Crystal Report to PDF Programatically
This one is the irisreports it has 63 cases..
Public Sub irisreports(ByVal ReportNo As Integer)
On Error GoTo errSub
Dim repDateFrom As Date
Dim repDateTo As Date
Select Case ReportNo
Case 1
'item master listing alphabetical
SendParamToCrystal glob.store_name, MDIForm1.CrystalReport1, "parCompanyName", 0
SendParamToCrystal glob.store_address1 & " " & glob.store_address2, MDIForm1.CrystalReport1, "parCompanyAddress", 1
With MDIForm1.CrystalReport1
'.SQLQuery = "Select t_invtran.*,t_item.* from t_invtran inner join t_item on t_invtran.f_barcode=t_item.f_barcode " _
' & "WHERE t_invtran.f_barcode='" & Me.txtItemMaster(1).Text & "'"
.ReportFileName = App.Path & "\reports\ItemMasterList.rpt"
If MsgBox("Do you like to view the report?", vbYesNo + vbQuestion) = vbYes Then
.Destination = crptToWindow
Else
.Destination = crptToPrinter
End If
.Action = 1
End With
Re: Export Crystal Report to PDF Programatically
This one i think the report that i wanted to generate straight to pdf. thanks in advance for your help.
Private Sub rptDepartmentSalesSummary()
frmCashManagement.crRepGrossProfit.ReportFileName = App.Path & "\reports\repDepartmentSalesSummary.rpt"
SendParamToCrystal "From " & frmCashManagement.monthSalesReport(0).Value & " TO " & frmCashManagement.monthSalesReport(1).Value, frmCashManagement.crRepGrossProfit, "parrepTitle", 1
SendParamToCrystal frmCashManagement.monthSalesReport(0).Value, frmCashManagement.crRepGrossProfit, "parFrom", 2
SendParamToCrystal frmCashManagement.monthSalesReport(1).Value, frmCashManagement.crRepGrossProfit, "parTo", 3
frmCashManagement.crRepGrossProfit.Destination = crptToWindow
frmCashManagement.crRepGrossProfit.WindowState = crptMaximized
frmCashManagement.crRepGrossProfit.WindowShowGroupTree = False
frmCashManagement.crRepGrossProfit.Action = 1
End Sub
Re: Export Crystal Report to PDF Programatically
Ok
Your project is using Crystal Reports version 8.5 or lower and using the OCX control
In order to solve your problem to automatically export to pdf, you should upgrade to Crystal Reports version 10 or 11 and also modify your project acordingly
Re: Export Crystal Report to PDF Programatically
Hi is there an alternative? it actually exports on pdf via crystal report. the problem with that is if it goes directly to crystal report it shows the data of the report before you can export it to pdf. is there a way where i can generate the report but hide the details of the report when it is viewed? so i wont need to upgrade it to CR 10 or 11.
1 Attachment(s)
Re: Export Crystal Report to PDF Programatically
I remember I had the same problems several years ago (almost 12) and the solution I posted was the easiest and fastest
If your code is organized in procedures, you need to change only a few lines and add a reference to CR...
You actually use OCX and you should use RDC... here's an small document to read
Re: Export Crystal Report to PDF Programatically
Thanks for that info sir. However I don't have that much knowledge in programming language. But I'll look into the file you sent me. If I didn't get it right would you be interested to have this requirement done for me. I'm willing to pay for the job if your interested. Thanks and regards. (: