| Assignments | Hints and Corrections | Outputs | Requirements |

Step 1: Creating Data Environment Designer

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.

Click to see Report EnviromnentTo create a simple hierarchical cursor in the Data Environment designer:

  1. Retrieve the Sound Advice.vbp project from your floppy disk.
  2. 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.
  3. 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.
  4. 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.
  5. Click the Next button to get to the Connection tab.
  6. Click the ellipsis button (...) next to the first text box.
  7. 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.
  8. Click OK to close the dialog box.
  9. Right-click the Connection1 icon, and click Rename. Change the name of the icon to SoundAdvice.
  10. 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
  1. Click OK to close the dialog box.
  2. 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
  1. Click OK to close the dialog box.
  2. 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
  1. Click OK to close the dialog box.
     
  2. 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:

  1. 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.
  2. 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.
  3. Set the properties of the DataReport object according to the table below:
Property Setting
Name rptSoundAdviceCustomers
Caption Sound Advice Customer Report
  1. On the Properties window, click DataSource and then click deSoundAdvice. Then click DataMember and click Customers.
  2. 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.
  3. Right-click the Data Report designer, and click Retrieve Structure.
  4. Change the Report Width property in the Property Window to 9000 twips.
  5. 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.
  6. From the Data Environment designer, drag the Customer ID field (under the Customers command) onto the Detail (Customers_Detail) section.
  7. The Detail (Customers_Detail) section can contain any field from the Customers command.
  8. 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.
  9. 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.
  10. 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
    .
  11. 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.
  12. 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.
  13. 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.
  14. 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.
  15. 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.
  16. 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.
  17. 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.
  18. 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".
  19. Resize the Data Report designer's sections to use as little space as possible in each of the report bands.
  20. Click to see Report EnviromnentIt'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.

  21. Save the project.

Step 3: Preview the Data Report Using the Show Method

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

  1. On the Project Explorer window, double-click the frmCustomers icon to display the Form designer.
  2. On Toolbox, click the General tab.
  3. 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.
  4. Click the CommandButton icon and draw a CommandButton on the Customer form between the Update and the Close command buttons.
  5. Set the properties of the Command1 control according to the table below:
Property Setting
Name cmdReport
Caption Report
  1. In the button's Click event, paste the code below.
Private Sub cmdReport_Click()
rptSoundAdviceCustomers.Show
End Sub
  1. Save and run the project.
  2. Click Report to display the report in print preview mode.

  1. 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 |