VB data report initial experience

Source: Internet
Author: User
Tags constant definition

The data report function is not described in detail. If you plan to create a classroom curriculum management tool during the holidays, you must output a curriculum, so you must use data reports. After one day of study, from online materials to msdn, although there are still many places that are not very clear, but a simple report has been successfully output. Here we will briefly discuss the general process.

First, a data report must have a data source (datasouse) that binds the data report to a dataset. I use rst as an ADODB. recordset as a data report data source. The second is the sections object set. The index from top to bottom increases progressively from 1. You can also use the ("Section1") method, which is basically similar to the method used to retrieve fields from a dataset, the next step is to operate the items in the section. I am not very clear about the order of the items, but you can use the type ...... Is to determine, usually rtplabel as the field name, rpttextbox as the data, so that you can determine which item to output. But I didn't use it in my example.

There are 7 fields in the database, and 5 fields are output in the report, including name, house electricity, phone number, mobile phone number, and address. when the report is too large, you have to make a judgment. You are lazy ......, The five labels are also set, from name to address, corresponding to five texts, without any binding. Next, connect to the database and obtain the dataset. Let the code speak. ^_^

Private sub report_click ()
Dim CNN as new ADODB. Connection 'defines the connection and DataSet object. If you do not understand this, we recommend that you check the VB dim rst as new ADODB. recordset 'database programming? ^_^
Dim STR as string
Dim intctrl as integer 'get the number of items in the Section

STR = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & App. Path & "/card. mdb; persist Security info = false"
CNN. cursorlocation = aduseclient
CNN. Open Str
Set rst = CNN. Execute ("select * From Table1 ")

With datareport1
Set. datasource = rst' set the data source of datareport to the current Dataset
. Datamember = ""
With. Sections ("Section1"). Controls


. Item (1). datafield = RST. Fields ("name"). name' assigns values to the datafield of text in the section in sequence.
. Item (2). datafield = RST. Fields (""). name' loop output, which I learned for a long time.
. Item (3). datafield = RST. Fields ("phone"). name' how can he avoid loops? ^_^
. Item (4). datafield = RST. Fields ("Mobile Phone"). Name
. Item (5). datafield = RST. Fields ("Address"). Name

End
End
Datareport1.refresh

Datareport1.show show reports

End sub

The following is a constant definition and error parameter that I have found on msdn. I hope it will help ^_^

 

Data Report designer constant

 

Alignment constant

Constant Value Description
Rptjustifyleft 0 The text is left aligned.
Rptjustifyright 1 Right-aligned text.
Rptjustifycenter 2 Text center.

Asynchronous type constant

Constant Value Description
Rptasyncpreview 0 Preview mode. Before callingShowMethod.
Rptasyncprint 1 Indicates that a task has been sent to the printer.
Rptasyncexport 2 Indicates that a file is being exported.

Constant of the background Style

Constant Value Description
Rptbktransparent 0 Controls are transparent.
Rptbkopaque 1 The widget is not transparent.

Border Style Constant

Constant Value Description
Rptbstransparent 0 The border is transparent.
Rptbssolid 1 The border is a solid line.
Rptbsdashes 2 The border consists of dotted lines.
Rptbsdots 3 A border consists of vertices.
Rptbsdashdot 4 The border is composed of dashes.
Rptbsdashdotdot 5 A border consists of two dashes.

Error constant

Constant Value Description
Rpterraccessdenied 8513 (& h2141) Access denied.
Rpterrboundctlnotallowed 8551 (& h2167) Controls cannot be placed in this part.
Rpterrchapterinit 8521 (& h2149) You Cannot initialize this chapter.
Rpterrcollectionisempty 8573 (& h217d) The set is empty.
Rpterrcreatingfont 8556 (& h216c) An error occurred while creating the font.
Rpterrcreatingwindow 8572 (& h217c) An error occurred while creating the window.
Rpterrduplicatekey 8500 (& h2134) The set contains duplicate key values.
Rpterrexportformatsempty 8506 (& h213a) The exportformats set is empty.
Rpterrfilealreadyexists 8512 (& h2140) The file already exists.
Rpterrgeneralfileio 8510 (& h213e) File I/O error.
Rpterrinvalidarg 8507 (& h213b) An invalid parameter.
Rpterrinvalidcolindex 8523 (& h214b) The column index is invalid.
Rpterrinvaliddatafield 8526 (& h214e) The data field cannot be found.
Rpterrinvaliddatesource 8520 (& h2148) The data source is invalid.
Rpterrinvalidfilefilter 8517 (& h2145) The file filter is invalid or an invalid format.
Rpterrinvalidfileversion 8511 (& h213f) The file version is invalid.
Rpterrinvalidkey 8504 (& h2138) The keyword is invalid.
Rpterrinvalidname 8503 (& h2133) Invalid name.
Rpterrinvalidpropertyvalue 380 (& h17c) The property value is invalid.
Rpterrinvalidrowindex 8524 (& h214c) The row index is invalid.
Rpterrinvalidrowset 8522 (& h214a) The row set is invalid.
Rpterrinvalidtemplate 8516 (& h2144) The exportformat template is invalid.
Rpterrkeynotfound 8501 (& h2135) The keyword cannot be found.
Rpterrlinebreak 8553 (& h2169) An error occurred while changing the text in the control.
Rpterrmarginstootall 8541 (& h215d) The top and bottom margins are higher than the height of the paper.
Rpterrmarginstoowide 8540 (& h215c) The left and right margins are wider than the width of the paper.
Rpterrnotallowedinreportgenerating 8576 (& h2180) This attribute or method cannot be accessed when a report is generated.
Rpterrobjectnotfoundincollection 8574 (& h217e) The object cannot be found in the collection.
Rpterroutofmemory 7 Memory overflow.
Rpterrpathnotfound 8514 (& h2142) Path not found.
Rpterrprint 8558 (& h216e) An error occurred while printing.
Rpterrprinterinfo 8555 (& h216b) An error occurred while obtaining printer information.
Rpterrprintinit 8557 (& h216d) An error occurred while initializing the printer.
Rpterrreporttootall 8571 (& h217b) Some are not suitable for pages in the vertical direction.
Rpterrreporttoowide 8542 (& h215e) The report width is wider than the paper width.
Rpterrsectdontmatchdata 8570 (& h217a) The report does not match the data source.
Rpterrsharingviolation 8515 (& h2143) Files cannot be accessed because they are used by other processes.
Rpterrsubscriptrange 9 Subscript out of bounds.
Rpterrtempfilename 8550 (& h2166) An error occurred while generating the temporary file name.
Rpterrtempfileread 8554 (& h216a) An error occurred while opening or reading the temporary file.
Rpterrtempfilewrite 8552 (& h2168) An error occurred while creating or writing temporary files.
Rpterrtypemismatch 13 Type mismatch.
Rpterrunexpected 8505 (& h2139) Unexpected errors.
Rpterrunknown 8502 (& h2136) General error.

Export format constant

Constant Value Description
Rptfmthtml 0 HTML format.
Rptfmttext 1 Text format.
Rptfmtunicodetext 2 Unicode.
Rptfmtunicodehtml_utf8 3 HTML encoded using the universal character set (UTF-8.

Function type constant

Constant Value Description
Rptfuncsum 0 Aggregate functions.
Rptfuncave 1 Average.
Rptfuncmin 2 Minimum value.
Rptfuncmax 3 Maximum value.
Rptfuncrcnt 4 Count the rows in the Section.
Rptfuncvcnt 5 Count fields that contain non-null values.
Rptfuncsdev 6 Calculate the standard deviation.
Rptfuncserr 7 Calculation standard error.

Line skew constant

Constant Value Description
Rptslantnwse 0 The line is tilted from the northwest to the southeast.
Rptslantnesw 1 The line is tilted from the northeast to the southwest.

Paging constant

Constant Value Description
Rptpagebreaknone 0 There is no page.
Rptpagebreakbefore 1 A page is displayed before the part.
Rptpagebreakafter 2 A page is displayed after the part.
Rptpagebreakbeforeandafter 3 The front and back pages are displayed.

Page range constant

Constant Value Description
Rptrangeallpages 0 Print or export all pages.
Rptrangefromto 1 Only print or export pages within the specified range.

Image Alignment constant

Constant Value Description
Rptpatopleft 0 The image is displayed in the upper left corner.
Rptpatop 1 The image is displayed in the upper part.
Rptpatopright 2 The image is displayed in the upper right corner.
Rptparight 3 The image is displayed on the right.
Rptpabottomright 4 The image is displayed in the lower right corner.
Rptpabottom 5 The image is displayed at the bottom.
Rptpabottomleft 6 The image is displayed in the lower left corner.
Rptpaleft 7 The image is displayed on the left.
Rptpacenter 8 The image is displayed in the middle.

Shape constant

Constant Value Description
Rptshprectangle 0 Rectangular shape.
Rptshpsquare 1 Square shape.
Rptshpoval 2 Elliptical shape.
Rptshpcircle 3 Circular shape.
Rptshproundedrectangle 4 Rectangular shape of the rounded corner.
Rptshproundedsquare 5 Square shape of the rounded corner.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.