• Tidak ada hasil yang ditemukan

Directory listing of http: uap.unnes.ac.id ebook biblebook Visual Basic 6 com & Library Books

N/A
N/A
Protected

Academic year: 2017

Membagikan "Directory listing of http: uap.unnes.ac.id ebook biblebook Visual Basic 6 com & Library Books"

Copied!
30
0
0

Teks penuh

(1)

Building Reports

Co ntrary to po pular belief, paper repo rts are far fro m dead. Yo ur applic atio ns need the ability to pro duc e repo rts fro m their database. Mic ro so ft Data Repo rt is the answer. Mic ro so ft Data Repo rt is a full-featured repo rt generato r who se features inc lude:

Controls – inc ludes the familiar Label, Shape, Image, TextBox, and Linec o ntro ls used in c reating Visual Basic fo rms, plus the Functionc o ntro l that allo ws yo u to c o mpute the sum, average, minimum o r maximum value fo r a database field.

(2)

Print pre vie w – allo ws yo ur users to see what their repo rts will lo o k like befo re they print them.

File e xport– means that yo u c an save the generated repo rt as a text file o r as an HTML file that c an be displayed o n yo ur Web site.

Asynchronous ope ration– permits yo ur repo rts to run in the bac kgro und while yo ur users c o ntinue to use their applic atio n fo r o ther tasks.

Using the Data Report Designer

To c reate a data r epo rt, yo u use the Data Repo rt Designer in Visual Basic . Yo u start by c reating a data so urc e and an instanc e o f the Data Repo rt Designer. Typic ally, yo u will want to use the Data Enviro nment Designer disc ussed in Chapter 9 to c reate the data so urc e.

Getting your data

In o rder to c reate a repo rt, yo u must first add a Data Enviro nment Designer to yo ur applic atio n. Then yo u need to c reate a Commando bjec t that will retrieve the data yo u want to inc lude in yo ur repo rt. The Commando bjec t c an c o ntain c hild c o m-mands to c reate a hierarc hic al rec o rdset.

Building a data report’s structure

To add a data repo rt to yo ur applic atio n, c ho o se Pro jec t ÿ Add Data Repo rt. Then the Data Repo rt Windo w will appear o n yo ur sc reen (see Figure 10-1). This windo w repre-sents a virtual view o f yo ur repo rt. It is bro ken into a series o f sec tio ns that c o ntains c o ntro ls that will display the data fro m yo ur data so urc e. No te that I inc luded eac h o f the sec tio n types in Figure 10-1. The gro up header and fo o ter sec tio ns must be manu-ally added to the repo rt.

Re port he ade r – is printed o nly o nc e at the very beginning o f the repo rt. ✦Page he ade r– is printed at the to p o f eac h page o f the repo rt. This sec tio n is

generally used fo r things like page title.

Group he ade r– is printed at the beginning o f a new gro up o f data. A gro up sec tio n c o rrespo nds to a Commando bjec t in a hierarc hic al rec o rdset, o r may inc lude the RptFunctionc o ntro l to summarize data fro m a c o lumn in ano ther Commando bjec t.

(3)

Group foote r– is printed at the end o f a gro up o f data. It c o rrespo nds to the gro up header sec tio n.

Page foote r– is printed at the bo tto m o f eac h page o f the repo rt. ✦Re port foote r– is printed o nly o nc e at the end o f the repo rt.

Figure 10-1: The Data Report Window

Growing groups: By default, no groups are included in your report. If you right click on the report and choose Insert Group Header/ Footer, you can add a new group to the report.

Binding the data report to the data source

The very first thing yo u sho uld do after c reating a data repo rt is to bind the data repo rt to yo ur data so urc e. Yo u do this by setting the values fo r the DataSource and DataMemberpro perties in the no rmal Visual Basic Pro perties windo w. The DataSourcepro perty sho uld be bo und to the DataEnvironmento bjec t and the DataMemberpro perty sho uld be bo und to the Commando bjec t that retrieves the info rmatio n yo u want to display in the repo rt. All o f the c o ntro ls yo u use in yo ur repo rt will auto matic ally use these values to retrieve the data fo r the repo rt.

Grouping data: You should use a hierarchical Command object if you w ish to define groups in your reports. Each level above the low est level in the hierarchical com m and w ill correspond to a group section in the report.

(4)

Adjusting the structure to fit your data

Onc e yo u define the DataSourcefo r yo ur repo rt, yo u c an right c lic k o n the repo rt and c ho o se Retrieve Struc ture fro m the po p-up menu. This will add gro up sec tio ns to yo ur repo rt to ac c o mmo date the hierarc hic al rec o rdset fro m yo ur data so urc e. No te that retrieving the struc ture will erase any c o ntro ls yo u have o n the repo rt. Yo u do n’t need to use the Retrieve Struc ture func tio n when yo u’re using a regular rec o rdset, bec ause the default repo rt do esn’t inc lude any data.

Yo u c an also manually add o r delete sec tio ns to yo ur repo rt by right c lic king o n the repo rt and selec ting o r deselec ting the sec tio n fro m the po p-up menu. This is useful when yo u do n’t want to use a sec tio n, suc h as the Repo rt Header and Fo o ter.

Where did that space come from?: If you only need a header or footer section but not both, you should set the height of the one you don’t w ant to zero. This m eans that it w on’t take up space in your report.

Yo u c an use the Insert Gro up Header/ Fo o ter o n the po p-up menu to add a gro up sec tio n to yo ur repo rt. If yo u already have a gro up o n yo ur repo rt, a dialo g bo x will be displayed, asking yo u where the new gro ups sho uld be plac ed ( see Figure 10-2) . Simply press the up o r do wn arro ws to mo ve the new gro up up o r do wn in the gro up hierarc hy. If the gro up c an’t be mo ved up o r do wn in the hierarc hy, the appro priate arro w will be disabled.

Figure 10-2: Placing a new group in your report

Placing controls on your report

There are two main ways to add c o ntro ls to yo ur repo rt. The easiest metho d is to add them auto matic ally by dragging Commando bjec ts and/ o r fields fro m the Data Enviro nment Designer o nto the repo rt in the appro priate sec tio n and then mo ve

(5)

them to where yo u wo uld like the info rmatio n to appear. The o ther way is to add c o ntro ls manually to yo ur repo rt fro m the To o lbo x and then bind them to the data so urc e.

Automatically adding controls

Onc e yo u have b o und yo ur repo rt to a Commando b jec t in the Data Enviro nment Designer, yo u c an drag the o b jec t o ver to a sec tio n in yo ur repo rt and the designer will auto matic ally add all o f the fields in the sec tio n. If yo u had the Drag and Dro p Field Captio ns c hec k b o x marked in the Data Enviro nment Designer Optio ns win-do w, lab els fo r eac h field will also b e c reated. The c o ntro ls will b e arranged in a single c o lumn, and the height o f the sec tio n will auto matic ally b e adjusted to ac c o mmo date the c o ntro ls if there isn’t suffic ient spac e ( see Figure 10-3) .

Figure 10-3: Dropping controls on a report

(6)

Creating column headers: By default, dragging a field from the Commandobject w ill also drag along a RptLabelfield w ith the nam e of the field. The RptLabel control is sim ilar to a Label control in that it w ill alw ays display a constant text value. In m any cases, you w ill w ant to m ove the RptLabelcontrol from the sec-tion in w hich you dropped the controls to a secsec-tion higher in the report hierarchy. For instance, you m ight w ant to m ove the labels from the Detail section to the Page Header section or to a group section. See the next section, “Manually Adding Controls,” for an explanation of the RptLabelcontrol.

If yo u have a hierarc hic al rec o rdset, yo u must mo ve the Commando b jec ts o ne at a time into the appro priate sec tio ns. The designer wo n’t let yo u mo ve a Command o b jec t c o ntaining c hild c o mmands to a Details sec tio n. It must b e mo ved to either a gro up header o r fo o ter sec tio n.

Yo u may also drag info rmatio n fro m the Data Enviro nment Designer o ne field at a time o nto the repo rt. I find this appro ac h mo re useful than dragging all o f the fields o ver at o nc e, bec ause it is easier to po sitio n eac h c o ntro l where I want, and I do n’t have all o f the o ther c o ntro ls c luttering the wo rk area.

M anually adding controls

In additio n to dragging info rmatio n fro m the Data Enviro nment Designer, yo u c an also manually add c o ntro ls fro m the standard Visual Basic To o lbo x. These c o ntro ls are kept in a new sec tio n o n the to o lbo x kno wn as the DataRepo rt sec tio n ( see Figure 10-4) . The c o ntro ls available in the to o lbo x inc lude:

RptLabe l– displays a label o n yo ur repo rt with a fixed blo c k o f text. ✦RptTe xtBox– displays a value fro m yo ur database.

RptImage– displays an image o n yo ur repo rt. No te that this field c an’t be bo und to a field in yo ur database.

RptLine– displays a line o n yo ur repo rt. This is useful when yo u want to sepa-rate o ne area o f yo ur repo rt fro m ano ther.

RptShape– displays a shape ( rec tangle, square, c irc le, o r o val) o n yo ur repo rt. This c an be used to draw attentio n to a partic ular area o n yo ur repo rt. ✦RptFunction– c o mputes the sum, average, minimum value, o r maximum

value o f a c o lumn in yo ur database. This c o ntro l must be used o nly in a gro up fo o ter o r a repo rt fo o ter sec tio n.

These c o ntro ls are disc ussed in their respec tive sec tio ns to ward the end o f this c hapter.

(7)

Figure 10-4: View ing the DataReport toolbox

Setting control properties

Eac h o f the Data Repo rt c o ntro ls has pro perties just like traditio nal c o ntro ls. The pro perties fo r eac h c o ntro l are displayed in the Pro perties windo w, just as they wo uld b e fo r any o ther c o ntro l. Yo u sho uld review the pro perties o f any c o ntro l yo u add manually to make sure that their values are appro priate fo r ho w yo u plan to use them.

They’re different too:While the nam es of the controls in the Data Report are sim -ilar to the nam es of the controls you use in a Visual Basic form , they are signifi-cantly different. The Data Report controls are often m issing various properties or have slightly different definitions for others. For instance, w hile the TextBox con-trol has a Textproperty, the RptTextBoxcontrol doesn’t. Don’t assum e that the controls are the sam e. Refer to “The Data Report Object Model” later in this chap-ter for all of the details about each control.

Binding relationships: The RptTextBoxand RptFunctioncontrols are useless unless they are bound to a data source. Since the DataReport object itself is already bound to a data source, you need to bind the RptTextBox and RptFunctioncontrol’s DataFieldproperty to the appropriate field from your data source. Also, you need to select the function that the RptFunctioncontrol w ill perform on the bound data.

Note Caution

Rpt Label Rpt Text Box Rpt Image

Rpt Line Rpt Shape

(8)

Adding shortcut controls

In additio n to the c o ntro ls listed ab o ve, the Data Repo rt Designer inc ludes so me useful sho rtc uts to predefined RptLabelc o ntro ls. These sho rtc uts are no t avail-ab le in the to o lb o x, b ut c an b e ac c essed b y mo ving yo ur mo use po inter o ver the sec tio n o f the repo rt yo u wish to c hange and right c lic king to display a po pup menu. Then yo u c an c ho o se the sho rtc ut yo u want. The fo llo wing sho rtc uts may b e availab le:

Curre nt Page Numbe r– displays the c urrent page number ( %p) .

Total Numbe r of Page s– displays the to tal number o f pages in the repo rt (%P). ✦Curre nt Date (Short Format)– displays the c urrent date using the Windo ws

sho rt date fo rmat ( %d) .

Curre nt Date (Long Format) – displays the c urrent date using the Windo ws lo ng date fo rmat ( %D) .

Curre nt Time (Short Format)– displays the c urrent time using the Windo ws sho rt time fo rmat ( %t) .

Curre nt Time (Long Format) – displays the c urrent time using the Windo ws lo ng time fo rmat ( %T) .

Re port Title– displays the value in the DataReport’s Titlepro perty ( %i) .

Build your own: You can also add any of the form at codes (%p, %P, and so on) listed above to your ow n RptLabelcontrol.

Percent complete: In order to display a percent sign (%) in a RptLabelcontrol, you need to enter it tw ice (%%).

Programming Your Report

Mo st o f the wo rk o f building a repo rt is do ne using the Data Repo rt Designer. Very little c o de is required to use this fac ility.

Previewing a report

Displaying a repo rt in a preview windo w requires no thing mo re than a c all to the Showmetho d, as sho wn belo w:

DataReport1.Show Note

(9)

This c all is easily inserted as a menu item in yo ur pro gram o r in the Clickevent o f a c o mmand butto n. Running the Showmetho d displays the first page o f the repo rt in the preview windo w, as sho wn in Figure 10-5. In additio n to the sc ro llbars, users c an press butto ns to print the repo rt, expo rt the repo rt to a disk file, c o ntro l the zo o m level, o r selec t whic h page they want to view.

Figure 10-5: Show ing the preview of your report

Window sizing:While this m ay seem obvious, the default size of the Data Report Preview w indow is the sam e size as the w indow used by the Data Report Designer. Also, rem em ber to allow for the w idth of the m argins for your printer w hen choosing the initial size of the Print Preview w indow.

Printing a Report

While the user c an press the Print b utto n o n the Preview windo w to send the repo rt to the printer, yo u c an do the same thing in yo ur o wn c o de b y using the PrintReportmetho d. The fo llo wing c o de will sho w the Print dialo g b o x displayed in Figure 10-6. If yo u do n’t display the Print dialo g b o x ( in o ther wo rds, if the ShowDialogparameter is set to False) , the repo rt will b e sent direc tly to the printer.

Cookie = DataReport1.PrintReport (True, rptRangeAllPages) Tip

Page Print

Export

(10)

Figure 10-6: Show ing the Print dialog box to the user

The value returned by the PrintReportmetho d is kno wn as a Cookie. It allo ws yo u to trac k this partic ular repo rt task using the vario us events that o c c ur while the repo rt is being pro c essed. This c an be impo rtant, sinc e it is po ssible to run sev-eral repo rts c o nc urrently. Witho ut the Cookievalue, yo u wo uldn’t be able to iden-tify whic h repo rt triggered an event.

Yo u c an also spec ify whic h pages yo u want to print when yo u use the PrintReport metho d. If yo u display the Print dialo g bo x by setting the ShowDialogparameter to True, the user c an o verride any o f the default parameters fo r the printer and any o ther values yo u spec ified as parameters.

Exporting reports

In additio n to sending yo ur repo rts to the printer, yo u c an also expo rt them to a disk file. Yo u c an c reate either a regular text file o r an HTML file. Bo th types o f files c an be c reated with regular c harac ters o r with Unic o de c harac ters.

Yo u c an expo rt a repo rt by c alling the ExportReportmetho d, using c o de like this:

Cookie = DataReport1.ExportReport (rptKeyHTML, _ “d:\vb6db\Chapter10\MSReport\report1.HTM”, _ True, False, rptRangeFromTo, 1, 3)

(11)

Tracking asynchronous activity

Rec all that asynchro no us o pe ratio npermits yo ur repo rts to run in the bac kgro und while yo ur users c o ntinue to use their applic atio n fo r o ther tasks. Also keep in mind that the Data Repo rt fac ility o perates independently o f yo ur applic atio n pro -gram. This means that yo ur user c an c o ntinue to wo rk with yo ur applic atio n while the repo rt is being generated and printed. Yo u c an trac k the pro gress o f the repo rt in yo ur applic atio n by using the AsyncProgressevent, as sho wn in Listing 10-1. No te that o ne o f the values passed to the event is the same Cookievalue that was returned by the metho d that c reated the repo rt o r expo rt task.

Listing 10-1:

The DataReport_AsyncProgress event

Private Sub DataReport_AsyncProgress _

(ByVal JobType As MSDataReportLib.AsyncTypeConstants, _ ByVal Cookie As Long, ByVal PageCompleted As Long, _ ByVal TotalPages As Long)

Form1.ProgressBar1.Min = 0

Form1.ProgressBar1.Value = PageCompleted Form1.ProgressBar1.Max = TotalPages

End Sub

The Data Report object model

The Data Repo rt Designer is based aro und an o bjec t c alled DataReport. This o bjec t c o ntains a number o f different pro perties, metho ds, and events that c o ntro l ho w yo ur repo rt is generated.

Forming an object:The DataReportobject is based on the Formobject and it inherits all of the sam e properties, m ethods, and events.

DataReport properties

The DataReporto bjec t c o ntains many different pro perties. I’ve listed the key o nes fo r this o bjec t in Table 10-1.

(12)

Table 10-1

Properties of the DataReport Object

Key Properties of the DataReport

ObjectProperty Description

AsyncCount A Longvalue containing the num ber of asynchronous operations still executing.

BottomMargin A Longvalue containing the size of the bottom m argin in tw ips.

Caption A Stringvalue containing the value that w ill be displayed in the DataReport’s title bar.

DataMember A Variantvalue containing the data m em ber of the DataSourcethat w ill be used to generate the report.

DataSource A Variantcontaining the data source for the report.

ExportFormats An object reference to an ExportFormats

collection that contains the type of export form ats available.

Font An object reference to a Fontobject that w ill be used as the default font for the report.

LeftMargin A Longvalue containing the size of the left m argin in tw ips.

ReportWidth A Longvalue containing the total w idth of the report in tw ips.

RightMargin A Longvalue containing the size of the right m argin in tw ips.

Sections An object reference to a Sectionscollection containing inform ation about the various sections of the report.

Title A Stringvalue containing the title of the report.

TopMargin A Longvalue containing the size of the top m argin in tw ips.

Twips are for kids: Visual Basic uses the twipas the fundam ental unit of m ea-surem ent w hen placing controls on a form or report. A tw ip is 1/ 20 of a point or 1/ 1440 of an inch. A pixel is the sm allest elem ent that can be displayed on a screen or a printer. Pixels depend on the characteristics of the device they are being displayed on, w hile a tw ip is independent of any physical device.

(13)

DataReport methods

The DataReporto bjec t has a number o f metho ds. Listed belo w are the o nes that are the mo st impo rtant when using Data Repo rt in yo ur applic atio n.

Function ExportReport ([FormatIndexOrKey], [FileName], [Overwrite As

Boolean = True], [ShowDialog As Boolean = False], [Range As

PageRangeConstants], [PageFrom], [PageTo]) As Long

The ExportReportmetho d writes the text part o f a repo rt to a disk file. The return value is kno wn as a Cookie, whic h is used to identify the spec ific data repo rt pro -c ess. This value will be used in vario us events to allo w yo u to identify whi-c h repo rt triggered the event.

Not saved: Any im ages or shapes that you include in your printed report w ill not be saved in your exported report.

FormatIndexOrKeyis a Variantc o ntaining either a referenc e fo r an ExportFormat o bjec t o r a Stringthat is o ne o f the fo llo wing: rptKeyHTML(“key_def_HTML”), expo rt the repo rt in standard HTML fo rmat; rptKeyText(“key_def_Text”), expo rt the repo rt as a regular text file; o r rptKeyUnicodeHTML_UTF8 (“key_def_ UnicodeHTML_UTF8). If this value is no t spec ified, the Expo rt dialo g bo x will be displayed.

FileNameis a Stringc o ntaining the name o f the file to be displayed. If this value isn’t spec ified, the Expo rt dialo g bo x will be sho wn.

Overwriteis a Booleanvalue when TRUEmeans that if the file spec ified by FileNameexists, it will auto matic ally be o verwritten.

ShowDialogis a Booleanvalue when TRUEmeans that the Expo rt dialo g bo x will be displayed.

Rangeis an enumerated data type. A value o f rptRangeAllPages( 0) will print all o f the pages in the repo rt ( default) , while a value o f rptRangeFromTo( 1) will print o nly the pages spec ified in the PageFromand PageToparameters.PageFromis a Longvalue c o ntaining the starting page number used when Rangeis set to rptRangeFromTo( 1) .

PageTois a Longvalue c o ntaining the ending page number used when Rangeis set to rptRangeFromTo( 1) .

(14)

Function PrintReport ([ShowDialog As Boolean = False], [Range As

PageRangeConstants], [PageFrom], [PageTo]) As Long

The PrintReportmetho d is used to send a c o py o f the repo rt to the default sys-tem printer. The return value is kno wn as a Cookie, whic h is used to identify the spec ific data repo rt pro c ess. This value will be used in vario us events to allo w yo u to identify whic h repo rt triggered the event.

ShowDialogis a Booleanvalue when TRUEmeans that the Print dialo g bo x will be displayed.

Rangeis an enumerated data type. A value o f rptRangeAllPages( 0) will print all o f the pages in the repo rt ( default) , while a value o f rptRangeFromTo( 1) will print o nly the pages spec ified in the PageFromand PageToparameters.PageFromis a Longvalue c o ntaining the starting page number used when Rangeis set to rptRangeFromTo( 1) .

PageTois a Longvalue c o ntaining the ending page number used when Rangeis set to rptRangeFromTo( 1) .

Sub Refresh ( )

The Refreshmetho d is used to repro c ess the repo rt and repaint the display.

Sub Show ([M odal], [OwnerForm])

The Showmetho d displays the Data Repo rt fo rm as the repo rt’s Print Preview windo w.

Modalis an Integerthat determines ho w the Preview windo w is displayed. A value o f vbModal( 1) will freeze all ac tivity in the applic atio n until the Preview windo w is c lo sed, while vbNormal( 0) allo ws the applic atio n to c o ntinue running while the Preview windo w is displayed. If no t spec ified, vbNormalis assumed.

OwnerFormis a Stringc o ntaining the name o f the o wner fo rm. The default value fo r this argument is “Me”.

Key DataReport events

(15)

Event AsynchProgress (JobType as AsynchTypeConstants, Cookie As

Long, PageCompleted As Long, TotalPages As Long)

The AsynchProgressevent is c alled when the Data Repo rt pro c ess has finished generating a page o f the repo rt.

Where am I?:You m ay w ant to use this event to update a progress bar that indi-cates how m uch of the report has been processed.

JobTypeis an enumerated data type who se value is rptAsyncPreview( 0) when a preview o peratio n is being pro c essed, rptAsyncPrint( 1) when a print repo rt o peratio n is being pro c essed, o r rptAsyncReport( 2) when an expo rt o peratio n is being pro c essed.

Cookieis a Longvalue that identifies the spec ific repo rt jo b.

PageCompletedis a Variantc o ntaining the number o f pages that have been c o mpleted.

TotalPagesis a Variantc o ntaining the to tal number o f pages to be pro c essed.

Event Error (JobType as AsynchTypeConstants, Cookie As Long, ErrObj

As RptError, ShowError As Boolean)

The Errorevent is c alled when the Data Repo rt pro gram enc o unters an erro r.

JobTypeis an enumerated data type who se value is rptAsyncPreview( 0) when a preview o peratio n is b eing pro c essed, rptAsyncPrint( 1) when a print repo rt o peratio n is b eing pro c essed, o r rptAsyncReport( 2) when an expo rt o peratio n is b eing pro c essed.

Cookieis a Longthat identifies the spec ific repo rt jo b.

ErrObjis an RptErroro bjec t c o ntaining the details o f the erro r that triggered this event.

ShowErroris a Boolean, whic h when set to TRUEwill display the erro r info rmatio n to the user in a dialo g bo x.

Event ProcessingTimeout (Seconds As Long, Cancel As Boolean,

JobType as AsynchTypeConstants, Cookie As Long)

The ProcessingTimeoutevent is fired perio dic ally while the repo rt is being gener-ated. Yo u c an examine the amo unt o f time that the jo b has been running and c ho o se whether o r no t to c anc el the repo rt pro c ess.

(16)

Secondsis a Longvalue c o ntaining the number o f sec o nds sinc e the repo rt pro c ess was started.

Cancelis a Boolean, whic h when set to TRUEwill c anc el the repo rt pro c ess.

JobTypeis an enumerated data type who se value is rptAsyncPreview(0) when a preview o peratio n is being pro c essed, rptAsyncPrint(1) when a print repo rt o pera-tio n is being pro c essed, o r rptAsyncReport(2) when an expo rt o peratio n is being pro c essed.

Cookieis a Longvalue that identifies the spec ific repo rt jo b.

Controls collection properties

The Controlsc o llec tio n is an o bjec t that c o ntains o bjec t referenc es to the c o ntro ls sto red in a partic ular Sec tio n o bjec t. Table 10-2 lists the pro perties o f the Controls c o llec tio n. No te that c o ntro ls c an’t be added o r deleted at runtime.

Table 10-2

Properties of the Controls Collection

Property Description

Count A Longvalue containing the num ber of controls in the collection.

Item An object reference to one of the control objects (RptFunction, RptImage, RptLabel, RptLine,

RptShape,and RptTextBox).

ExportFormat object properties

The ExportFormato bjec t c o ntains info rmatio n abo ut a single expo rt fo rmat. Table 10-3 lists the vario us pro perties asso c iated with the ExportFormato bjec t.

ExportFormats collection properties

(17)

Table 10-3

Properties of the ExportFormat Object

Property Description

FileFilter A Stringvalue containing the list of file extensions that w ill be used in the file filter. If m ore than one file extension is used, they m ust be separated by sem icolons (;). For exam ple:

“*.HTM”is a valid value.

FileFormatString A Stringvalue containing the text value displayed in the Export dialog box’s Save As type box that corresponds to the list extensions listed in FileFilter. For exam ple: “Web Report (*.HTM)”is a valid value for this property.

FormatType An enum erated data type containing the type of export form at. Legal values are: rptFmtHTML(0), export the report using the regular HTM L form at; rptFmtText(1), export the report as a text file; rptFmtUnicodeText(2), export the report as a Unicode text file; rptFmtUnicodeHTML_UTF8

(3), export the report using an HTM L form at w ith the UTF – 8 Unicode character set.

Key A Stringthat uniquely identifies the export form at.

String A Stringcontaining the tem plate that w ill be used to export the report.

Table 10-4

Properties of the ExportFormat Object

Property Description

Count A Longvalue containing the num ber of objects in the collection.

Item(key) An object reference to an ExportFormatobject containing inform ation about a particular export form at, w here key

contains a reference to the ExportFormatobject.

ExportFormats collection methods

(18)

Function Add (Key As String, FormatType As ExportFormatTypeConstants,

FileFormatString As String, FileFilter As String, [Template] ) As ExportFormat

The Addmetho d c reates a new ExportFormato bjec t and inserts it into the ExportFormatsc o llec tio n.

Keyis the key value that will be used to lo c ate the new ExportFormato bjec t.

FormatTypeis an enumerated data type desc rib ing the type o f fo rmat sto red in the o b jec t: rptFmtHTML( 0) , expo rt the repo rt using the regular HTML fo rmat; rptFmtText( 1) , expo rt the repo rt as a text file; rptFmtUnicodeText( 2) , expo rt the repo rt as a Unic o de text file; rptFmtUnicodeHTML_UTF8( 3) , expo rt the repo rt using an HTML fo rmat with the UTF – 8 Unic o de c harac ter set. If this value is no t spec ified, the Expo rt dialo g b o x will b e displayed.

FileFormatStrongis a Stringvalue c o ntaining the text value displayed in the Expo rt dialo g bo x’s Save As type bo x that c o rrespo nds to the list extensio ns listed in FileFilter. Fo r example: “Web Report (*.HTM)”wo uld be a valid value fo r this argument.

FileFilteris a Stringvalue c o ntaining the list o f file extensio ns that are asso c i-ated with the expo rt fo rmat. If mo re than o ne file extensio n is used, they must be separated by semic o lo ns ( ;) and the first extensio n is the default extensio n. Fo r example: “*.HTM”is a valid value.

Templateis a Stringvalue c o ntaining the template that will be used when so me-o ne uses this expme-o rt fme-o rmat. If nme-o t spec ified, an empty string will be assumed.

Sub Clear ( )

The Clearmetho d remo ves all o f the members o f the c o llec tio n.

Sub Insert (Format As ExportFormat)

The Insertmetho d adds an ExportFormato bjec t to the c o llec tio n. Formatis an ExportFormato bjec t c o ntaining info rmatio n to be added to the c o llec tio n.

Sub Remove (Key)

(19)

RptError object properties

The RptErroro bjec t c o ntains erro r info rmatio n abo ut an erro r that o c c urred while pro c essing a repo rt. Table 10-5 lists the vario us pro perties asso c iated with the RptErroro bjec t.

Table 10-5

Properties of the RptError Object

Property Description

Description A Stringvalue containing a textual description of the error.

ErrorNumber A Longvalue containing error num ber value.

HelpContext A Longcontaining the help context for the error, w hich w ill contain m ore inform ation about the error.

HelpFile A Stringcontaining the nam e of the help file associated w ith

HelpContext.

Source An object reference to the object that caused the error.

RptFunction control properties

The RptFunctionc o ntro l is used to c o mpute a value based o n a series o f values retrieved fro m the database. Table 10-6 lists the vario us pro perties asso c iated with the RptFunctiono bjec t.

Critical properties: DataFieldshould be set to the appropriate field from your data source and FunctionTypeshould be set to the calculation you w ould like to apply to the data prior to running a report.

Table 10-6

Properties of the RptFunction Control

Property Description

Alignment An enum erated value describing how the contents of the control w ill be displayed. Legal values are: rptJustifyLeft(0),

rptJustifyRight(1), and rptJustifyCenter(2).

BackColor A Longvalue containing the color value for the background of the control.

Continued

(20)

Table 10-6

(continued)

Property Description

BackStyle An enum erated data type containing the style of the background. Legal values are: rptTransparent(0) and rptOpaque(1).

BorderColor A Longvalue containing the color value for the border surrounding the control.

BorderStyle An enum erated data type describing the style of the border surrounding the control. Legal values are: rptBSTransparent(0),

rptBSSolid(1), rptBSDashes(2), rptBSDots(3),

rptBSDashDot(4), rptBSDashDotDot(5).

CanGrow A Booleanvalue, w hen TRUEm eans that the height of the control w ill autom atically be increased if the size of the text exceeds the default height of the control.

DataField A Stringvalue containing the nam e of the database field w hich the function w ill be applied to.

DataFormat An object reference to a StdDataFormatobject containing the inform ation on how to form at the data displayed by the control.

DataMember A Stringvalue containing the nam e of the data m em ber of the data source that w ill be used as the source of data for the control.

Font An object reference to a Fontobject that describes the font inform ation used to display the value of the control.

ForeColor A Longcontaining the color that the text w ill be displayed in.

FunctionType An Integervalue identifying the function used w ith the field specified by DataFieldto com pute the value that w ill be displayed by this control. Legal values are: rptFuncSum(0), com putes the sum of the values in DataField; rptFuncAve(1), com putes the average of the values in DataField; rptFuncMin(2), finds the m inim um value of the values in DataField; rptFuncMax(3), finds the m axim um value of the values in DataField; rptFuncRCbt

(4), counts the num ber of row s retrieved in this section;

rptFuncVCnt(5), counts the num ber of row s retrieved in this section w hose values are not Null; rptFuncSDEV(6), com putes the standard deviation of the values in DataField; rptFuncSERR(7), com putes the standard error of the values in DataField.

Height A Longcontaining the height of the control in tw ips.

(21)

Property Description

Name A Stringcontaining the nam e of the control.

RightToLeft A Boolean, w hen TRUEm eans that the text w ill be displayed right to left in a bi-directional version of Window s.

Top A Longcontaining the distance betw een the top edge of the section and the top edge of the control.

Visible A Boolean, w hen TRUEm eans that the control w ill be displayed at runtim e.

Width A Longcontaining the w idth of the control in tw ips.

RptImage control properties

The RptImagec o ntro l is used to display a static image o n yo ur repo rt. Table 10-7 lists the vario us pro perties asso c iated with the RptImageo bjec t.

Critical properties: You should set the Pictureproperty to the im age you w ant to see at design tim e. Then you should adjust the SizeMode and Picture Alignmentif needed to m ake sure that the picture is displayed properly.

Table 10-7

Properties of the RptImage Control

Property Description

BackColor A Longvalue containing the color value for the background of the control.

BackStyle An enum erated data type containing the style of the background. Legal values are: rptTransparent(0) and rptOpaque(1).

BorderColor A Longvalue containing the color value for the border surrounding the control.

BorderStyle An enum erated data type describing the style of the border surrounding the control. Legal values are: rptBSTransparent(0);

rptBSSolid(1); rptBSDashes(2); rptBSDots(3);

rptBSDashDot(4); rptBSDashDotDot(5).

Height A Longcontaining the height of the control in tw ips.

Left A Longcontaining the distance betw een the left edge of the report and the left edge of the control.

Continued

(22)

Table 10-7

(continued)

Property Description

Name A Stringcontaining the nam e of the control.

Picture An object reference to an IPictureDispobject.

PictureAlignment An enum erated data type describing how the picture w ill be positioned in the control. Legal values are: rptPATopLeft(0), position the im age at the top left corner; rptPATop(1), position the im age at the top center edge; rptPATopRight(2), position the im age at the top right corner; rptPARight(3), position the im age at the right center corner; rptPABottomRight(4), position the im age at the bottom right corner; rptPABottom(5), position the im age at the bottom center edge; rptPABottomLeft(6), position the im age at the bottom left corner; rptPALeft(7), position the im age at the left center edge; rptPACenter(8), center the im age in the control.

SizeMode An enum erated type describing how the im age w ill be displayed in the control. Legal values are: rptSizeClip(0), the im age w ill be clipped to fit inside the control; rptSizeStretch(1), the im age w ill be stretched to fill the control; rptSizeZoom(2), the im age w ill be stretched to fill the control, but the im age’s height to w idth proportion w ill rem ain unchanged.

Top A Longcontaining the distance betw een the top edge of the section and the top edge of the control.

Visible A Boolean, w hen TRUEm eans that the control w ill be displayed at runtim e.

Width A Longcontaining the w idth of the control in tw ips.

RptLabel control properties

The RptLabelc o ntro l is used to display a c o nstant text value o n yo ur repo rt. Table 10-8 lists the vario us pro perties asso c iated with the RptLabelo bjec t.

Critical properties: Enter the text you w ant to display in Caption. Next, set the Alignmentproperty to position text properly w ithin the label. If there is too m uch text for the label, then either resize the control on the Report Designer w indow or set the CanGrowproperty to TRUEto display all of the text.

(23)

Table 10-8

Properties of the RptLabel Control

Property Description

Alignment An enum erated value describing how the contents of the control w ill be displayed. Legal values are: rptJustifyLeft(0),

rptJustifyRight(1), and rptJustifyCenter(2).

BackColor A Longvalue containing the color value for the background of the control.

BackStyle An enum erated data type containing the style of the background. Legal values are: rptTransparent(0) and rptOpaque(1).

BorderColor A Longvalue containing the color value for the border surrounding the control.

BorderStyle An enum erated data type describing the style of the border surrounding the control. Legal values are: rptBSTransparent(0),

rptBSSolid(1), rptBSDashes(2), rptBSDots(3),

rptBSDashDot(4), rptBSDashDotDot(5).

CanGrow A Booleanvalue, w hen TRUEm eans that the height of the control w ill autom atically be increased if the size of the text exceeds the default height of the control.

Caption A Stringvalue containing the text that w ill be displayed by this control.

Font An object reference to a Fontobject that describes the font inform ation used to display the value of the control.

ForeColor A Longcontaining the color that the text w ill be displayed in.

Height A Longcontaining the height of the control in tw ips.

Left A Longcontaining the distance betw een the left edge of the report and the left edge of the control.

Name A Stringcontaining the nam e of the control.

RightToLeft A Boolean, w hen TRUEm eans that the text w ill be displayed right to left in a bi-directional version of Window s.

Top A Longcontaining the distance betw een the top edge of the section and the top edge of the control.

Visible A Boolean, w hen TRUEm eans that the control w ill be displayed at runtim e.

(24)

Fortune favors the bold: In m ost cases, you should display the text in a label in bold to help set apart colum n headers and other text from the data in the detail section.

RptLine control properties

The RptLinec o ntro l is used to draw a line o n yo ur repo rt. Yo u define a rec tangle using the Heightand Widthpro perties and the line will be drawn fro m o ne c o rner to the diago nal. Whic h c o rners are used depends o n the LineSlantpro perty. Table 10-9 lists the vario us pro perties asso c iated with the RptLinec o ntro l.

Critical properties: Adjust the LineSlant to change the direction of the line. Note that a control w hose w idth is only one tw ip tall w ill be displayed as a hori-zontal line w ithout a slant.

Table 10-9

Properties of the RptLine Control

Property Description

BorderColor A Longvalue containing the color value of the line.

BorderStyle An enum erated data type describing how the line w ill be draw n. Legal values are: rptBSTransparent(0), rptBSSolid(1),

rptBSDashes(2), rptBSDots(3), rptBSDashDot(4),

rptBSDashDotDot(5).

Height A Longcontaining the height of the control in tw ips.

Left A Longcontaining the distance betw een the left edge of the report and the left edge of the control.

LineSlant An enum erated type describing w hich corners w ill be used to draw the line. Legal values are: rptSlantNWSE, the line w ill be draw n from the top left to the bottom right; rptSlantNESW, the line w ill be draw n from the top right to the bottom left.

Name A Stringcontaining the nam e of the control.

Top A Longcontaining the distance betw een the top edge of the section and the top edge of the control.

Visible A Boolean, w hen TRUEm eans that the control w ill be displayed at runtim e.

Width A Longcontaining the w idth of the control in tw ips. Tip

(25)

RptShape control properties

The RptShapec o ntro l is used to draw a shape o n yo ur repo rt. Yo u define a rec tan-gle using the Heightand Widthpro perties and then c ho o se the shape that will fill the rec tangle using the Shapepro perty. If yo u c ho o se to draw a c irc le o r a square, then the shape will start in the upper-left c o rner o f the rec tangle yo u drew and its size will be dic tated by the width o r height, whic hever is smaller. Table 10-10 lists the vario us pro perties asso c iated with the RptShapec o ntro l.

Critical properties: Shapeshould be set to the shape you w ant to display.

Table 10-10

Properties of the RptShape Control

Property Description

BackColor A Longvalue containing the color value for the background of the control.

BackStyle An enum erated data type containing the style of the background. Legal values are: rptTransparent(0) and rptOpaque(1).

BorderColor A Longvalue containing the color value of the line.

BorderStyle An enum erated data type describing how the shape w ill be draw n. Legal values are: rptBSTransparent(0), rptBSSolid(1),

rptBSDashes(2), rptBSDots(3), rptBSDashDot(4),

rptBSDashDotDot(5).

Height A Longcontaining the height of the control in tw ips.

Left A Longcontaining the distance betw een the left edge of the report and the left edge of the control.

Name A Stringvalue containing the nam e of the control.

Shape An enum erated data type that identifies the shape that w ill be draw n on the report. Legal values are: rptShpRectangle(0),

rptShpSquare(1), rptShpOval(2), rptCircle(3),

rptShpRoundedRectangle(4), rptShpRoundedSquare(5).

Top A Longcontaining the distance betw een the top edge of the section and the top edge of the control.

Visible A Boolean, w hen TRUEm eans that the control w ill be displayed at runtim e.

(26)

RptTextBox control properties

The RptTextBoxc o ntro l is used to display a value fro m the database o n yo ur repo rt. Table 10-11 lists the vario us pro perties asso c iated with the RptTextBox o bjec t.

Critical properties: The DataFieldproperty should be set to the field from your data source that w ill be displayed in the text box.

Table 10-11

Properties of the RptLabel Control

Property Description

Alignment An enum erated value describing how the contents of the control w ill be displayed. Legal values are: rptJustifyLeft(0),

rptJustifyRight(1), and rptJustifyCenter(2).

BackColor A Longvalue containing the color value for the background of the control.

BackStyle An enum erated data type containing the style of the background. Legal values are: rptTransparent(0) and rptOpaque(1).

BorderColor A Longvalue containing the color value for the border surrounding the control.

BorderStyle An enum erated data type describing the style of the border surrounding the control. Legal values are: rptBSTransparent(0),

rptBSSolid(1), rptBSDashes(2), rptBSDots(3), rptBSDashDot

(4), rptBSDashDotDot(5).

CanGrow A Booleanvalue, w hen TRUEm eans that the height of the control w ill autom atically be increased if the size of the text exceeds the default height of the control.

Font An object reference to a Fontobject that describes the font inform ation used to display the value of the control.

ForeColor A Longcontaining the color that the text w ill be displayed in.

Height A Longcontaining the height of the control in tw ips.

Left A Longcontaining the distance betw een the left edge of the report and the left edge of the control.

Name A Stringvalue containing the nam e of the control.

RightToLeft A Boolean value, w hen TRUE, m eans that the text w ill be displayed right to left in a bi-directional version of Window s.

(27)

Property Description

Top A Longcontaining the distance betw een the top edge of the section and the top edge of the control.

Visible A Boolean, w hen TRUEm eans that the control w ill be displayed at runtim e.

Width A Longcontaining the w idth of the control in tw ips.

Section object properties

The Sectiono bjec t c o ntains info rmatio n abo ut ho w a sec tio n is displayed o n the repo rt. See Table 10-12 fo r the pro perties available in this o bjec t.

Table 10-12

Properties of the Section Object

Property Description

Controls An object reference to a Controlscollection containing inform ation about the set of controls displayed in the section.

ForcePageBreak An enum erated type describing how page breaks w ill be taken for the section. Values are: rptPageBreakNone(0), no page breaks are taken; rptPageBreakBefore(1), the page break occurs before the section; rptPageBreakAfter(2), the page break occurs after the section; rptPageBreakBeforeAndAfter(3), the page break occurs before and after the section.

Height A Longvalue containing the height of the section in tw ips.

KeepTogether A Booleanvalue, w hich w hen set to TRUEforces the entire section to fit on the sam e page. If there isn’t sufficient room , a new page w ill be started.

Name A Stringvalue containing the nam e of the section.

Visible A Boolean, w hich w hen set to TRUEm eans the report section is visible at runtim e.

Sections collection properties

(28)

Table 10-13

Properties of the Controls Collection

Property Description

Count A Longvalue containing the num ber of Sectionobjects in the collection.

Item An object reference to the Sectionobject.

Thoughts on the Data Report Feature

A tool like Microsoft Data Report is im portant to m any application developers. With the em phasis today on building graphical applications that can provide inform ation on dem and that elim inates the need for paper reports, program m ers often forget that som etim es hav-ing a paper report is critical.

Som e types of reports deserve to be archived on paper, even if they are never looked at. For exam ple, consider an audit log. Having a paper audit trail m ay be the only w ay to prove that som eone unauthorized changed inform ation in your database. Also, for som e high profile applications, having a paper report available m ay allow the user to continue operating in the event of a catastrophic system failure. Failure to plan for this type of situation is the sign of a poor job analyzing the user’s true needs.

Of course, there are m any cases w here actual reports are critical. Printing receipts from a point of sale system , as w ell as printing packing lists for the w arehouse and invoices for accounts receivable, are all cases w here a w ell-designed paper report is im portant. While it is possible to do this by using the Printobject in Visual Basic and m anually building the code to do the job, using Data Report is a m uch m ore efficient use of a program m er’s tim e.

(29)

Summary

In this c hapter yo u learned the fo llo wing:

✦Yo u c an use the Data Repo rt Designer to design a repo rt graphic ally just like yo u design a fo rm fo r a Visual Basic pro gram.

✦Yo u c an extrac t the info rmatio n fo r the repo rt using the Data Enviro nment Designer.

✦Yo u c an define vario us sec tio ns o n the repo rt to help yo u summarize yo ur data.

✦Yo u c an plac e fields o n the repo rt by dragging them fro m the Data Enviro nment Designer.

✦Yo u c an allo w the user to preview the repo rt befo re sending it to the printer. ✦Yo u c an also expo rt yo ur repo rt to a text file o r an HTML file.

(30)

Gambar

Figure 10-1: The Data Report Window
Figure 10-2: Placing a new group in your report
Figure 10-3: Dropping controls on a report
Figure 10-4: Viewing the DataReport toolbox
+7

Referensi

Dokumen terkait

Adapun tujuan diadakannya indeks saham syariah sebagaiman Jakarta Islamic Index yang melibatkan 30 saham terpilih, yaitu sebagai tolak ukur untuk mengukur kinerja

You can download and install the soft file of this incredible book Time Mends (Timber Wolves, Book 2) By Tammy Blackwell currently and in the link offered.. Yeah, different with

Indonesia merupakan negara dengan orang muslim terbesar didunia, akan tetapi setiap ormas muslim sendiri tentunya berbeda dalam memutuskan suatu masalah baru yang muncul

54 Tahun 2010 tentang Pengadaan Barang/Jasa Pemerintah serta menindaklanjuti proses seleksi untuk Paket Pekerjaan Pengadaan Meubelair (985 Unit) , bersama ini kami

n salinannya sebagaimana tertuang dalam lam proses pembuktian kualifikasi

Uang merupakan uang milik masyarakat atau uang beredar di masyarakat (di luar Bank Sentral seperti Bank Indonesia dan perbankan atau semua bank), yang terdiri dari :.. Uang Kertas

Puji syukur kami panjatkan kepada Tuhan Yang Maha Esa atas limpahan rahmat dan hidayah-Nya sehingga Prosiding Seminar Nasional MIPA Universitas Negeri Yogyakarta

As everybody recognizes, book Carr: Five Years Of Rape And Murder By Edna Buchanan is very popular as the window to open up the globe. It implies that reading publication Carr: