|
Assignments |
Hints and Corrections |
Outputs |
Requirements |
Perform steps 1, 4, 5, and 12-14 from pages VB
6.66 - VB 6.67 of your book, substitute the steps listed below
for the other steps listed on those pages. In Place of the Crystal
Report Control discussed in Chapter 6 of your book ,
Microsoft has developed its own Report module discussed below.
This topic creates the customer data report using a Data
Environment designer as a data source. The Data
Environment designer uses the Sound Advice database developed in the
lab steps 1 and 2 to create a simple report. The three reports
require the use of three tables, Customers, Employees, and
Compact Discs. Only the exact steps are specified for the
Customer Report. Follow the same procedure to create the Employee
and Compact Disc reports. The finished reports resemble the
figures on page VB 6.67 of your book.
Customer Report containing the following
fields: Customer ID, Name, Address, City, State, Zip Code,
Balance and Employee ID.
Before you begin the step-by-step process,
ensure that the Sound Advice database (Sound Advice.mdb)
is present on your floppy. If it is not present, complete the in
the labs 1 and 2 from chapter 6 first.
To create a simple hierarchical cursor in
the Data
Environment designer:
- Retrieve the Sound Advice.vbp
project from your floppy disk.
- On the Project menu, click Add
Data Environment to add a designer to your project.
If the designer is not listed on the Project menu,
click Components. Click the Designers tab,
and click Data Environment to add the designer to
the menu.
- Note The first four kinds of
ActiveX designers loaded for a project are listed on the Project
menu. If more than four designers are loaded, the later
ones will be available from the More ActiveX Designers
submenu on the Project menu.
- Right-click on Connection1 to
display the short-cut menu, click on Properties.
On the Data Link Properties dialog box, click Microsoft
Jet 3.51 OLE DB Provider. This selects the correct
OLE DB provider for accessing a Jet database.
- Click the Next button to get to the
Connection tab.
- Click the ellipsis button (...) next to
the first text box.
- Use the Select Access Database dialog
box to navigate to the Sound Advice.mdb file, which
should be located on your floppy disk as a result of
completing in the labs 1 and 2 at the end of chapter 6.
- Click OK to close the dialog box.
- Right-click the Connection1 icon,
and click Rename. Change the name of the icon to SoundAdvice.
- Right-click the SoundAdvice icon,
and then click Add Command to display the Command1
dialog box. In the dialog box, set the properties as
shown below:
Property |
Setting |
Command Name |
Customers |
Connection |
Sound Advice |
DataBase Object |
Table |
Object Name |
Customers |
- Click OK to close the dialog box.
- Right-click the SoundAdvice icon,
and then click Add Command to display the Command1
dialog box. In the dialog box, set the properties as
shown below:
Property |
Setting |
Command Name |
Employees |
Connection |
Sound Advice |
DataBase Object |
Table |
Object Name |
Employees |
- Click OK to close the dialog box.
- Right-click the SoundAdvice icon,
and then click Add Command to display the Command1
dialog box. In the dialog box, set the properties as
shown below:
Property |
Setting |
Command Name |
CompactDiscs |
Connection |
Sound Advice |
DataBase Object |
Table |
Object Name |
CompactDiscs |
- Click OK to close the dialog box.
- Set the properties of the project and
designer according to the settings below, then save the
project:
Object |
Property |
Setting |
Project |
Name |
Sound Advice3 |
DataEnvironment |
Name |
deSoundAdvice |
Step 2: Creating the
Data Report (Customers)
Once the Data Environment designer has been
created, you can create a data report. Because all of the fields
in the data environment will be used in a report, this series of
topics creates a report that displays all the fields.
To create a new data report:
- On the Project menu, click Add
Data Report, and Visual Basic will add it to your
project. If the designer is not on the Project
menu, click Components. Click the Designers
tab, and click Data Report to add the designer to
the menu.
- Note The first four kinds of
ActiveX designers loaded for a project are listed on the Project
menu. If more than four designers are loaded, the later
ones will be available from the More ActiveX Designers
submenu on the Project menu.
- Set the properties of the DataReport object
according to the table below:
Property |
Setting |
Name |
rptSoundAdviceCustomers |
Caption |
Sound Advice
Customer Report |
- On the Properties window, click DataSource
and then click deSoundAdvice. Then click DataMember
and click Customers.
- Important To set the DataSource
property to deSoundAdvice, the Data Environment designer
must be open. If it is closed, press CTRL+R to display
the Project window, then double-click the data
environment icon.
- Right-click the Data Report designer, and
click Retrieve Structure.
- Change the Report Width property in
the Property Window to 9000 twips.
- Choose the Window top-menu
option and click on Tile Vertically.
This will place the Data Report Designer and the Data
Environment Designer on the screen next to each other.
Move and close other windows on your screen accordingly
to provide the best working environment.
- From the Data Environment designer, drag
the Customer ID field (under the Customers
command) onto the Detail (Customers_Detail)
section.
- The Detail (Customers_Detail) section
can contain any field from the Customers command.
- Move the Label control (leftmost Customer
ID box) (RptLabel) named Label1 to Page Header
(PageHeader) section right above the Customer ID
field in the Detail (Customers_Detail) section.
- If you do not want a Label control to be
included with the TextBox control, you can uncheck the Drag
and Drop Fields Caption option on the Field
Mapping tab of the Data Environment designer's Options
dialog box.
- From the Data Environment designer, drag
the Name field (under the Customers command)
onto the Detail (Customers_Detail) section. Move
the Label control (leftmost Name box) RptLabel) named Label2
to Page Header (PageHeader) section right
above the Name field in the Detail (Customers_Detail)
section
.
- From the Data Environment designer, drag
the Address field (under the Customers
command) onto the Detail (Customers_Detail)
section. Move the Label control (leftmost address box)
RptLabel) named Label3 to Page Header (PageHeader)
section right above the Address field in the Detail
(Customers_Detail) section.
- From the Data Environment designer, drag
the City field (under the Customers command)
onto the Detail (Customers_Detail) section. Move
the Label control (leftmost City box) RptLabel) named Label4
to Page Header (PageHeader) section right
above the City field in the Detail (Customers_Detail)
section.
- From the Data Environment designer, drag
the State field (under the Customers
command) onto the Detail (Customers_Detail)
section. Move the Label control (leftmost State box)
RptLabel) named Label5 to Page Header (PageHeader)
section right above the State field in the Detail
(Customers_Detail) section.
- From the Data Environment designer, drag
the Zip Code field (under the Customers
command) onto the Detail (Customers_Detail)
section. Move the Label control (leftmost Zip Code box)
RptLabel) named Label6 to Page Header (PageHeader)
section right above the Zip Code field in the Detail
(Customers_Detail) section.
- From the Data Environment designer, drag
the Balance field (under the Customers
command) onto the Detail (Customers_Detail)
section. Move the Label control (leftmost Balance box)
RptLabel) named Label7 to Page Header (PageHeader)
section right above the Balance field in the Detail
(Customers_Detail) section.
- From the Data Environment designer, drag
the Employee ID field (under the Customers
command) onto the Detail (Customers_Detail)
section. Move the Label control (leftmost Employee ID box)
RptLabel) named Label8 to Page Header (PageHeader)
section right above the Employee ID field in the Detail
(Customers_Detail) section.
- To put the title in the Report Header (ReportHeader)
section on the report perform the following steps. Right-click
in the Report Header (ReportHeader) section of the
report on the short-cut menu point to Insert Control
then click on Report Title.
This will put the title control in the Report Header (ReportHeader)
section of the report. Change the Caption property
of the control in the property window to read "CUSTOMER
REPORT". To put the date in the Report Header
(ReportHeader) section to appear under the CUSTOMER
REPORT header on the report perform the following steps.
Right-click in the Report Header (ReportHeader)
section of the report on the short-cut menu point to Insert
Control then click on Current
Date (Short Format). This will
put the date control in the Report Header (ReportHeader)
section of the report. Increase the width of this report
band and drag the date control under the CUSTOMER REPORT
header. See page VB 6.68 of your book to see the correct
format of the report header and the detail lines of the
report.
- To put your name, class, and section
number in the Report Footer (ReportFooter) section
on the report perform the following steps. Right-click in
the Report Footer (ReportFooter) section of the
report on the short-cut menu point to Insert Control
then click on Label. This will put a
label control in the Report Footer (ReportFooter)
section of the report. Change the Caption property
of the control in the property window to read "your
name IFS 110 section number".
- Resize the Data Report designer's
sections to use as little space as possible in each of
the report bands.
It's important to
resize the height of the Details section to be as
short as possible because the height will be multiplied
for every record in the Sound Advice database. Any extra
space below or above the detail line text boxes will
result in unneeded space in the final report.
- Save the project.
Now that the data environment and the data
report objects have been created, you are almost ready to run the
project. One step remains: to write code to show the data report.
To show the data report at run time
- On the Project Explorer window,
double-click the frmCustomers icon to display the
Form designer.
- On Toolbox, click the General tab.
- When you add a Data Report designer to
your project, its controls are added to the tab named DataReport.
To use the standard Visual Basic controls, you must
switch to the General tab.
- Click the CommandButton icon and
draw a CommandButton on the Customer form between
the Update and the Close command buttons.
- Set the properties of the Command1 control
according to the table below:
Property |
Setting |
Name |
cmdReport |
Caption |
Report |
- In the button's Click event, paste the
code below.
Private Sub cmdReport_Click()
rptSoundAdviceCustomers.Show
End Sub
- Save and run the project.
- Click Report to display the report
in print preview mode.
- Use the techniques listed above to set up
the Data Report Designers for the Employees
and Compact Discs tables in the Sound Advice
database and place the Report
command buttons on their corresponding forms. When
complete your project will contain one Data
Environment (Sound Advice) and three different Data
Reports representing the Customers, Employees
and Compact Discs tables in the Sound Advice
database.
|
Assignments |
Hints and Corrections |
Outputs |
Requirements |