Recent Posts

Showing posts with label Crystal Reports. Show all posts
Showing posts with label Crystal Reports. Show all posts

Tuesday, September 9, 2008

How to open a crystal reports from VB Application?

Instead of using crystal reports viewer we can directly open a crystal reports.

Sometimes we have to print the reports directly to the printers for the items
like printing the receipt.

In those cases we don't need to view the receipt on the screen.
Also some businesses require just to print the report, so that user can't
reprint the receipt again and put the transaction on cancelled transaction.

Also if you guys are wondering how to directly print the crystal reports to
the printer without opening the report then this is also solved in the
following example.

First add the crystalreports object named CReport in the form

Private Sub PrintReceipt(ByVal lngtranno As Long, strNewReg As String)
Dim CLName As String

Me.CReport.Connect = "dsn=testDSN;UID=test;PWD=test"
Me.CReport.SelectionFormula = "({Account.TranNo})=" & lngtranno & " AND

({Registration.RegNo})='" & strNewReg & "'"
Me.CReport.Formulas(0) = "OrgName='" & MDIMain.lblOrgName.Caption & "'"
Me.CReport.Formulas(1) = "User='" & MDIMain.lblUser.Caption & "'"

Me.CReport.ReportFileName = App.Path + "\Report\rptReceiptNew.rpt"
Me.CReport.DiscardSavedData = True
' Me.CReport.Destination = crptToPrinter
' Me.CReport.PrintReport


Me.CReport.WindowState = crptMaximized
Me.CReport.Action = 1

End Sub

In the above function PrintReceipt

first the report object is connected.
And the selection formula is provided to filter the data
Passing the values to the report fromulas
Providing the report path where the report is located.
Discard saved data will refresh the report with new data.

Destination provides where the report is to be printed
PrintReport prints the report directly.
( if you just want to show the report on sreen then disable these lines)





Read more!

Sunday, March 16, 2008

Passing data from SubReport to Main Report in Crystal Reports

In subReport Formula field

@Stuff Total

WhilePrintingRecords;
Shared NumberVar OrderTotal := Sum ({Orders.Order Amount})

In MainReport Formula Field

@GetTotalFromSubReport

WhilePrintingRecords;
Shared NumberVar OrderTotal;
NumberVar Total1998Amount;
Total1998Amount := Total1998Amount + OrderTotal;
Total1998Amount


Read more!