Beruflich Dokumente
Kultur Dokumente
I have a report that generates a list of items. I need to have the report count the number of items in the list.
Technique
Using the Data Report designer included with Visual Basic 6, you can create reports that can do various calculations based on the data in the report.
This How-To will demonstrate how to make a group based on the Authors field and add a calculated field that will display the number of books each author has written. This How-To will be a base demonstration how to add calculated fields to a Data Report.
Steps
Open and run DataProject.vbp, which displays the Figure 9.7. This displays each author's list of book and a count of the number of books per author. By using the toolbar at the top of the report you can print or export the report. 1. Start Visual Basic and select a new Data Project. This will add the Data Environment and Data Report to the project. Remove the form that was added to the project and set the Data Report as the Startup object. 2. From the Project menu select the Add Data Environment. Double-click on the DataEnvironment1 object that was added to the Project window. Right-click on the Connection folder and select the Add Connection item from the popup menu. Right-click on the Connection1 object and select the Properties item from the popup menu. Select the Microsoft Jet 3.51
OLE DB provider. The next dialog box that appears is used to find the BIBLIO.MDB file on your computer. Click the OK button. Right-click on the Command folder and select the Add Command item from the popup menu. Command1 will be added under the Commands folder. Right click on Command1 and select the Properties from the popup menu. Using the Data Object dropdown select the Tables item. Using the Object Name dropdown select the Titles item. Leccion 10.2 Agregando campos calculados Pgina 1
4. Set the DataMember and DataSource of the Data Report. Right-click on the bottom of the report and select the Retrieve Structure item from the popup menu. This will arrange the sections of the Data Report to match the data used. 5. Place the controls on the data report form. Set the properties of the controls as in Table 9.7.
Table 9.7. Objects and properties for drBasic.dsr. OBJECT Property Setting Pgina 2
Pgina 3
6. Run the project. It might take a few minutes to retrieve the data from the database.
How It Works.
The report retrieves the data from the Data Environment. The Data Environment queries the database and groups the data by author. The rptFunction control that has been placed in the Group footer displays the total number of books per author. The rptFunction control can do various functions as in Table 9.8.
Description Adds the values of the field Averages the values of the field Displays the minimum value of the field Displays the maximum value of the field Displays the number of rows in a section Pgina 4
Display the number of rows containing non-null values Display the standard deviation Display the standard error
The rptFunction can be used to do various calculations based on the type of data in the field. By placing the rptFunction control in either a group or report footer, you can perform calculations on fields contained in the report.
Comments Grouping is a very powerful function when generating reports. Grouping enables the report to list similar items together in the report. For Example, the books were not added sequentially in the database, so when retrieving a list of authors and their books from the database all the authors are mixed up in the list. Grouping allows report to present all the books for one author then another. Another example is when creating a report to list the books per publisher. The grouping would be done on publishers not authors.
Pgina 5