CIS 338: Printing
200 likes | 359 Vues
CIS 338: Printing. Dr. Ralph D. Westfall February, 2003. Create Print Reports 2 Ways. place fields on report layout manually interface is relatively easy to use or use retrieve structure automated layout easier to create summary fields such as subtotals within the report
CIS 338: Printing
E N D
Presentation Transcript
CIS 338: Printing Dr. Ralph D. Westfall February, 2003
Create Print Reports 2 Ways • place fields on report layout manually • interface is relatively easy to use • or use retrieve structure automated layout • easier to create summary fields such as subtotals within the report • makes it difficult to use code to get information from data source
Manual Report Layout • start new project • Project>References>Microsoft ActiveX Data Objects 2.[ ] Library, OK • Project>Components>Designers>Data Report, OK • add command button to form • double click button and add code
Manual Report Layout Code Dim cn As ADODB.Connection 'General Set cn = New ADODB.Connection 'Form_Load cn.ConnectionString = _ "Driver=Microsoft Access Driver (*.mdb);DBQ="_ & App.Path & "\[yourdatabase].mdb;" cn.Open dbquery2000.mdb
Manual Layout Code - 2 Dim sSQL As String 'General Dim rs As New ADODB.Recordset 'Command1_Click() sSQL = "select * from Payments where Date > #6-30-00#" Set rs = cn.Execute(sSQL)
Adding a Data Report • Project>Add Data Report • Data Report toolbox & Properties windows • Data Report Designer window parts • Report Header – titles etc. for whole report • Page Header – headings etc. for each page • Detail – data in report for each record • Page Footer – at page bottoms • Report Footer - after last report lines
Designing a Data Report • click RptLabel (tool) and draw on report • put label information into Caption property • click RptTextbox and draw on report • put name of a field in database into DataField property for each RptTextbox BldgNo AcctNo Payment
Data Report Code 'Command1_Click() Set DataReport1.DataSource = rs DataReport1.Show • run project and view report • note Print button at top of report • also Export button: save as HTML or text 'Notes
Enhancing a Data Report • what needs to be fixed? • make changes in layout, as necessary • can change RptTextBox and Label Font • click and drag Section boundaries to tighten spacing • move RptTextBoxes and Labels to fit into new boundaries
Enhancing a Data Report - 2 • special characters for label Captions • %p – current page number • %d – current short date (mm/dd/yy) • other date formats available • %t – current military time (e.g., 14:20) • other time formats available • %i – Title property of DataReport object • etc. 'p. 649
Enhancing a Data Report - 3 • RptImage (tool) to place image on page • click Picture property to identify source file • RptLine to draw lines on page • RptShape to draw geometric figures • Shape property identifies type of figure
Enhancing a Data Report - 4 • RptFunction (tool) adds summary fields • DataField property = database field name • FunctionType property for type of data • RptFuncSum, …Ave(rage) • …Min(imum), …Max(imum) • …RCnt – record count • etc. 'p. 652
Enhancing a Data Report - 5 • putting a variable into a header (p. 647) Dim strFirstDate strFirstDate = "10-30-02" DataReport1.Sections("Section4").Controls_("lblHeader").Caption = strFirstDate • put this code before DataReport1.Show • headers: Section4=report, Section2=page (or names you changed to) • lblHeaderis Name of a label control
Enhancing a Data Report - 6 • Crystal Reports packaged with VB • much more control over appearance • need to install Crystl32.exe from Visual Studio CD • runs from Add-Ins>Report Designer • very old version of Crystal Reports (4.6 or ?)
Automated Report Layout • Project>References>Microsoft Data Environment Instance 1.0>OK • may need to install SP4 to get this • Project>Components>Designers>Data Environment, OK • Project>Add Data Environment • right click Connection1 in Environment • set Provider to Microsoft Jet 4.0 OLE DB • browse for database name in Connection
Automated Report Layout - 2 • right click Connection1 >Add Command • right click Command1 >Properties • Database Object = View for query or Table • Object Name = QueryTotalDetail • Grouping tab • check Group Command Object • select BldgNo, SumOfPayment, click > , then click OK
Automated Report Layout - 3 • Project>Add Data Report • DataSource = DataEnvironment1 • DataMember=Command1_Grouping • right-click DataReport2 • click Retrieve Structure, Yes • Warning: destroys any previous layout and controls on this form
Automated Report Layout - 4 • tile Data Environment and DataReport2 • in the Data Environment, click on the plus sign (+) for the Summary fields in Command1_Grouping • click/drag BldgNo from Summary fields to DataReport2 Group Header • SumOfPayment -> Group Footer
Automated Report Layout - 5 • click and drag Detail field(s) into DataReport2 Detail e.g., Payment • note that you get 2 controls: label and text box • if necessary, use Ctrl key to select textbox and move away from label
Automated Report Layout - 6 • add another command button to form • put code in button's click event DataReport2.Show • run project and view report 2 • make changes in layout as necessary