Vous êtes sur la page 1sur 12

Creating Reports

In
Visual Basic

Version 1
1
Trg. Div., NIC HQRs
Different Ways of Creating
Reports
?Data Reports
?Crystal reports
?Preview Access Reports

Version 1
2
Trg. Div., NIC HQRs
Difference between DR and
CR
? Data Environment is a ?
Crystal Report is an Add-on
built-in utility with feature whose version 3.0 is
Visual Basic 6.0 coming bundled with 3rd CD of
enterprise edition. For higher
versions Crystal Report s/w has
to be procured.
? It is easy way to create ? It is more powerful than Data
simple reports. Report.
? Data fields can be ? Since it is an external tool so
dragged from the Data Data Environment can’t be used.
Environment created.
Version 1
3
Trg. Div., NIC HQRs
Steps for Creating Data Reports
? Open the Visual Basic Project
? Make the connection with the database using either
Data Environment or through ADO
? Add Data Report to the project
? If using Data Environment then in Report properties
– DataSource : <Data Environment name>
– DataMember : <Command name>
– Drag the fields from the command into the report
? If using ADO then
– Create the appropriate no. of textboxes on the report.
– In datafield property of textbox write the name of the
Version 1
field name as in Recordset.
Trg. Div., NIC HQRs
4
Steps for Working with Crystal Reports
? Create as shown in Crystal Report
? In the Visual Basic Project :
– Add Crystal Report control to the toolbox by selecting
Crystal Report Control 4.6 from the Components .
– Specify the report file name and the destination in the
Property page in ReportFileName property of Crystal
Report Control.
– Write the following line from where the report is to be
called.
? <Crystal Report Control name>.PrintReport

Version 1
5
Trg. Div., NIC HQRs
Something more with Reports…

? Computed fields can be added.


– Open the Properties of the Command of the Data
Environment.
– On the General tab, click the SQL Statement button,
and add the SQL statement, example is given as below:
Select empcode, empname, (basic * .42) As da from emp

Version 1
6
Trg. Div., NIC HQRs
Something more with Reports…

? Date,
Time, Page Number, and Title to the Data
Report can be added.
– Right-click the Data Report designer and click Show
Page Header/Footer, if it is not checked.
– Right-click the appropriate section and click Insert
Control.
– Click on appropriate control.

Version 1
7
Trg. Div., NIC HQRs
Something more with Reports…
? Built-in functions can be added to the report.
– Click on RptFunction control and drop it in your
Report Footer.
– Set the FunctionType property.
– Set the DataMember to appropriate command of the
Data Environment.

? Run-time parameters can be passed.

Version 1
8
Trg. Div., NIC HQRs
Something more with Reports…
? Grouped reports can be created
– Creating a group field in the Data Environment
designer.
– Adding a Group Header/Footer to the Data Report
designer to correspond to the new command.
– Resetting the DataMember property of the data
report to the new Grouping Command object created
in the data environment.
– Dragging the group field from the data environment
to the data report.
? Data from two tables can be taken.
Version 1
9
Trg. Div., NIC HQRs
Where the output can be taken ?
? On the Screen
– <datareportname>.show

? To the Printer
– <datareportname>.PrintReport([show dialog as
Boolean=False], [Range as Page Range
constants=rptRangeAllPages, PageFrom, PageTo])

? To an External File.
– <Datareportname>.ExportReport ([FormatindexorKey],
[filename], [Overwrite as Boolean], [show dialog as Boolean],
[Range as Page Range constants=rptRangeAllPages,
PageFrom, PageTo])

Version 1
10
Trg. Div., NIC HQRs
Passing Parameter in CR thruVB
? At the Crystal Report end
– Declare a parameter by Insert>>Parameter Field
option
– Specify selection formula by Report>>Edit Selection
formula>>Record.
? <fieldname><operator><?parameter name>
? At the VB end
– CrystalReport1.ReportFileName = “<Reportfile name
with path>”
– CrystalReport1.ParameterFields(0) = "<crystal report
parameter field name>;" & <vb variable/object value>
& ";TRUE"
– CrystalReport1.Destination = crptToWindow
– CrystalReport1.PrintReport
Version 1
11
Trg. Div., NIC HQRs
Preview Access Reports
• Incorporate the Reference to the MS-Access Object
Library
• Write the following code :
Private Sub Command1_Click()
Dim ac As Access.Application
Set ac = New Access.Application
ac.OpenCurrentDatabase <DataBaseName with Path>
ac.Visible = True
ac.DoCmd.OpenReport <ReportName>, acViewPreview
End Sub

Version 1
12
Trg. Div., NIC HQRs

Vous aimerez peut-être aussi