leccion 10.1 - creando un reporte con el diseñador de reportes

5
[VISUAL BASIC CON BASE DE DATOS] IDSYSTEMS 2012 Leccion 10.1 – Creando un reporte con el Diseñador de Reportes de Datos. Problem I need to create a report using data from a database that can be displayed to the user, easily printed or exported to HTML. Technique Using Visual Basic and the included Data Report Designer, a report can be created to represent the data as desired. Using the BIBLIO.MDB database included with Visual Basic, you will create a report that displays a list of authors. The preview window used to display the report will enable the user to print and export the report directly from the  preview. Steps Start Visual Basic, load then run the AuthorsDR.vbp project. Figure 9.2 displays how the report will look. The report can be printed by clicking the printer icon, or can be exported to text or HTML by clicking the  book icon. Figure 9.2 .   AuthorsDR   form shown at runtime. 1. Start Visual Basic and select a new Standard EXE project. Select Add Data Environment from the Project menu. The window in Figure 9.3 will appear. Right click on the Connection1 item in the Data View window. Select the Properties item from the popup menu. The following screen is used to set the database and connection type. This How-To will use the BIBLIO.MDB database; therefore, select the Microsoft Jet 3.51 OLE DB Provider, then click on the Next button. Enter or select the location of the BIBLIO.MDB database; it should  be in the same folder as Visual Basic. Click on the Test button to verify the connection. This handy option enables you to verify the database connection without having to write test codes. Run the project. Click the OK  button. 2. Right-click on the Commands folder in the Data Environment window. Select the Add Command item from the popup menu. An item called Command1 will appear under the Commands folder. Right click on it and select the Properties item from the  popup menu. The Properties dialog box that appears is used to select a table or query. Click the on Connection drop-down list and select Connection1. From the Database drop down select the Table object. From the Object drop-down list, select the Authors Table. The dialog should look like Figure 9.4 after the items have been chosen. Leccion 10.1 Creando reportes con el Diseñador de Reportes Página 1

Upload: idsystems

Post on 06-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

8/2/2019 Leccion 10.1 - Creando un reporte con el Diseñador de Reportes

http://slidepdf.com/reader/full/leccion-101-creando-un-reporte-con-el-disenador-de-reportes 1/5

[VISUAL BASIC CON BASE DE DATOS] IDSYSTEMS 2012

Leccion 10.1 – Creando un reporte con el Diseñador de Reportes de

Datos.

Problem

I need to create a report using data from a database that can be displayed to the user, easily printed or exported

to HTML.

Technique

Using Visual Basic and the included Data Report Designer, a report can be created to represent the data as

desired. Using the BIBLIO.MDB database included with Visual Basic, you will create a report that displays a list

of authors. The preview window used to display the report will enable the user to print and export the report

directly from the preview.

Steps

Start Visual Basic, load then run the AuthorsDR.vbp project. Figure 9.2 displays how the report will look.

The report can be printed by clicking the printer icon, or can be exported to text or HTML by clicking the

 book icon.

Figure 9.2.  AuthorsDR  form shown at runtime.

1. Start Visual Basic and select a new Standard EXE project. Select Add Data Environment from the

Project menu. The window in Figure 9.3 will appear. Right click on the Connection1 item in the Data

View window. Select the Properties item from the popup menu. The following screen is used to set the

database and connection type. This How-To will use the BIBLIO.MDB database; therefore, select the

Microsoft Jet 3.51 OLE DB Provider, then click on the Next button. Enter or select the location of the

BIBLIO.MDB database; it should be in the same folder as Visual Basic. Click on the Test button to

verify the connection. This handy option enables you to verify the database connection without having

to write test codes. Run the project. Click the OK  button.

2. Right-click on the Commands folder in the Data Environment window. Select the Add Command item

from the popup menu. An item called Command1 will appear under the Commands folder. Right click on

it and select the Properties item from the popup menu. The Properties dialog box that appears is used to

select a table or query. Click the on Connection drop-down list and select Connection1. From the

Database drop down select the Table object. From the Object drop-down list, select the Authors Table.

The dialog should look like Figure 9.4 after the items have been chosen.

Leccion 10.1 – Creando reportes con el Diseñador de Reportes Página 1

8/2/2019 Leccion 10.1 - Creando un reporte con el Diseñador de Reportes

http://slidepdf.com/reader/full/leccion-101-creando-un-reporte-con-el-disenador-de-reportes 2/5

[VISUAL BASIC CON BASE DE DATOS] IDSYSTEMS 2012

Figure 9.3. The  Data View Window.

Figure 9.4.  The  Command1 Properties dialog box.

3. From the Visual Basic main menu, select the Add Data Report item from the Project menu. Set the

 properties of the Data Report as in Table 9.5. Then, right-click on the report and select Retrieve

Structure from the popup menu. Retrieve Structure will make the sections of the report match the

Leccion 10.1 – Creando reportes con el Diseñador de Reportes Página 2

8/2/2019 Leccion 10.1 - Creando un reporte con el Diseñador de Reportes

http://slidepdf.com/reader/full/leccion-101-creando-un-reporte-con-el-disenador-de-reportes 3/5

[VISUAL BASIC CON BASE DE DATOS] IDSYSTEMS 2012

database connection layout.

Table 9.5. Properties for drBasic.dsr AuthorsDR.

OBJECT Property Setting

DataReport Name drBasic

DataMember Command1

DataSource DataEnvironment1

4. The fields to be displayed can be added in two ways. The first method is to draw the fields on thereport, then assign the proper DataMember and DataField  properties to them. The second method

is to open the Data Environment window, and drag and drop the fields directly on the report. After a

field is dropped onto the detail section of the report, the field and its caption are displayed on the report.Arrange the items as shown in Figure 9.5.

Figure 9.5.  Arranged   report objects.

5. Set the properties of the objects on the report form as in Table 9.6.

Table 9.6. Objects on drBasic.dsr.

Leccion 10.1 – Creando reportes con el Diseñador de Reportes Página 3

8/2/2019 Leccion 10.1 - Creando un reporte con el Diseñador de Reportes

http://slidepdf.com/reader/full/leccion-101-creando-un-reporte-con-el-disenador-de-reportes 4/5

[VISUAL BASIC CON BASE DE DATOS] IDSYSTEMS 2012

OBJECT Property Setting

RptCaption Name lbTitle

Font Arial

Size 12

Caption “List of Authors”

RptCaption Name lbAuthorTitle

Font Arial

Caption Author:

RptCaption Name lbYearTitle

Font Arial

Caption “Year Born:”

RptText Name txtAuthor

Font Arial

DataField Author

DataMember Command1

RptText Name txtYearBorn

Font Arial

DataField “Year Born”

DataMember Command1

DataSource DataEnvironment1

6. Remove the form called Form1 that was automatically created when you started Visual Basic. Set

the Startup Object to the report form. Run the project.

HOW IT WORKS

First, a Data Environment must be defined. This is the gateway through which the report retrieves its data.

Leccion 10.1 – Creando reportes con el Diseñador de Reportes Página 4

8/2/2019 Leccion 10.1 - Creando un reporte con el Diseñador de Reportes

http://slidepdf.com/reader/full/leccion-101-creando-un-reporte-con-el-disenador-de-reportes 5/5

[VISUAL BASIC CON BASE DE DATOS] IDSYSTEMS 2012

Then, the report is assigned to a Data Connection. The structure of the Data Connection is mirrored by the

report. Dragging and dropping the fields into the report creates the report layout. By running the Visual Basic

 project the report and data is displayed. At run-time the user can easily print or export the report.

Comments

Creating a Data report consists of three basic steps. First, a data connection must be created. This is the object

the report will use to retrieve the data. With Visual Basic 6 the new Data Environment is very powerful andflexible as it enables the Data Reports to retrieve data from various data types. You are not limited to just

Access MDB files, but can get data from any ODBC DataSource or use the built in functionality to connect

directly to an Microsoft SQL server or an Oracle database.

The second step is to assign the report to a Data Connector created in the Data Environment and use the

"Retrieve Structure" option so the report section matches the data connection.

The third step is to add the report controls to the report. These controls will display the data the report

retrieves. These controls can range from displaying the names of the fields to calculated items that

summarize data in the report.

Leccion 10.1 – Creando reportes con el Diseñador de Reportes Página 5