Simple use of CR in VB
Working with Crystal reports (which comes with VB) is sometimes very simple and sometimes very hard to do. But I have to use it (my boss is telling me that) so I just have given it a quick look. First it looks not very difficult; making a quick and simple report can be done just in - let's say - five minutes. The code I use to show the report is included on this page.
The way I use Crystal Reports is in combination with Visual Basic 5 Enterprise Edition and Sybase as database. I make some tempory views in code (this way the user can give some direction to the report). The reports I make as an example using all the fields that are in the view. That's the work I have to do before it can work. Calling Crystal Reports from the VB application is like this:
make sure you have the component linked to your project and add the control to the form
use the following code for calling the control and fill the report with the values:
Public Sub ExecuteSelectedReport(strSelected As String)
Const PROCEDURENAME As String = "ExecuteSelectedReport"
On Error GoTo ExecuteSelectedReport_FAIL
Screen.MousePointer = vbHourglass
If Not SelectGroupReport(strSelected) Then GoTo ExecuteSelectedReport_EXIT
'open and fill report
.ReportFileName = strTMPPath + strSelected + ".rpt"
.ReportTitle = frmStatistics.txtTitleReport.Text
.SQLQuery = "SELECT * FROM " + "VIEW" + strSelected
.PrinterCopies = 1
.PrinterCollation = crptDefault
.WindowControls = True
.WindowBorderStyle = crptSizable
.WindowControlBox = True
.WindowState = crptNormal
.WindowTitle = .ReportFileName
.Destination = crptToWindow
Screen.MousePointer = vbDefault
MsgBox Cstr(Err) + Error
The procedure 'SelectGroupReport(strSelected)' creates for me the view with the options the user have given (like period etc). The default report is called 'strSelected.rpt'; the view is also created with the same value. For the settings on the CrustalReports control you simple check teh Help-file. It is all there. You see it is not very difficult. Crystal reports gives you a lot of options to show with the report like saving it a text or even as a word document. Most work will be creating the views and making the default reports.