Crystal Reports™ 8.5 Developer's Guide
Crystal Reports™ 8.5 Developer's Guide
Crystal Reports™ 8.5 Developer's Guide
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Create and modify a report<br />
This code should appear in the Form_Load event procedure. It tells the viewer<br />
what report it should display and then it tells it to display (view) the report.<br />
Sub Form_Load()<br />
Private<br />
= vbHourGlass<br />
Screen.MousePointer<br />
= Report<br />
CRViewer1.ReportSource<br />
CRViewer1.ViewReport<br />
Screen.MousePointer = vbDefault<br />
End Sub<br />
This code should appear in the Form_Resize event procedure, it resizes the viewer<br />
every time the form is resized.<br />
Sub Form_Resize()<br />
Private<br />
= 0<br />
CRViewer1.Top<br />
= 0<br />
CRViewer1.Left<br />
= ScaleHeight<br />
CRViewer1.Height<br />
CRViewer1.Width = ScaleWidth<br />
End Sub<br />
5 To add selection criteria to the report. Edit the "Form2" declarations and<br />
"Form_Load" procedure to look like this:<br />
Report As New <strong>Crystal</strong>Report1<br />
Dim<br />
rs As New ADOR.Recordset<br />
Dim<br />
Sub Form_Load()<br />
Private<br />
= vbHourGlass<br />
Screen.MousePointer<br />
"Select * from customer where country = 'USA'", _<br />
rs.Open<br />
sample database"<br />
"xtreme<br />
rs,3,1<br />
Report.Database.SetDataSource<br />
= Report<br />
CRViewer1.ReportSource<br />
CRViewer1.ViewReport<br />
= vbDefault<br />
Screen.MousePointer<br />
Sub End<br />
This adds a query to select only the records with "USA" in the "Country" field.<br />
The recordset that results from that query will be passed to the report engine<br />
and the results displayed.<br />
6 Run the report again to see the changes. Your report should only contain USA<br />
data.<br />
7 Now we'll add a text object to the report and manipulate it using code. In the<br />
main Report Designer window, right-click just to the right of the graph in the<br />
Report Header pane and point to Insert, then select Text Object.<br />
8 Move the text object just above the pie graph. You may have to move the graph<br />
down a bit first. Make note of the Name in the Properties window. In this<br />
example, the name is "Text5" but the name in your project may be different.<br />
36 <strong>Crystal</strong> Reports Developer’s <strong>Guide</strong>