+ All Categories
Home > Documents > Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5...

Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5...

Date post: 27-Dec-2015
Category:
Upload: rosalyn-walsh
View: 216 times
Download: 0 times
Share this document with a friend
Popular Tags:
23
Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam Technologies Database
Transcript
Page 1: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Tutorial 5

Creating Complex Reports

Reporting on Data in the MovieCam Technologies Database

Page 2: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Objectives

• Introduction to Reports• Report Sections• Event Properties• Creating Numbered Lists• Subreports

Page 3: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Introduction: Creating a Report Master

• Very few CEO’s will actually work with the database but they will often review the many reports created to represent the database’s table. – report seen by the CEO has much less detail then those

seen by middle-level managers.– top-management wants a “big picture” view of how the

company is doing in sales. – mid-level managers will want the details of what region is

selling the most and/or what salespersons are performing the best and so on.

– may produce many different reports from the same set of data.

– use of report templates will help make existing and future reports much more adaptable.

Page 4: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Domain Aggregate Functions

• Domain - A set of records.• Domain aggregate functions - Functions that provide

statistical information for a domain• DLookUp function - used in the report template • syntax presented under the list of functions.

– the first two arguments, “expression” and “domain”, are required. third one, “criteria” is optional.

• The syntax is the same for each of these functions, only the function name changes.

• example DLookUp(“CompanyName”,”tblCorporate”,”ID=1” – DLookup function looks up and returns the CompanyName field

value from the tblCorporate table when the ID field value is equal to 1

Page 5: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

• DLookup – returns value in the specified field• DMin(),DMax() – returns minimum or maximum value in

specified field• DFirst(),DLast() – returns the value in specified field

from first or last physical record• DAvg() – returns arithmetic average of values in

specified field• DSum() - returns sum of values in specified field• DCount() - returns number of records with non-null

values in specified field

Domain Aggregate Functions

Page 6: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Report Sections

• Report Header Section - A section that appears once at the beginning of a report

• Page Header Section - A section that prints at the top of every page of the report.

• Detail Section - The main body of the report. It prints one time for each record in the report’s underlying record source (table or query).

• Page Footer Section - The section that appears at the bottom of every page of the report.

• Report Footer Section - The section that appears once at the end of the report.

Page 7: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Grouping Records in a Report

• Group Header Section - A section that appears at the beginning of a new group of records. Used to show information that applies to the group, such as a group name or a picture.

• Group Footer Section - A section that appears at the end of a group of records. Typically used to show calculations, such as a total or average of the records in the group.

Page 8: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

• report created will be based on query from next slide – good idea to create a query that contains the data wanted

in a report and then design a report to layout the data as desired.

• Can Grow property – set to yes, enables section or control to grow vertically so all data visible– When set for a control in a section, Access automatically

sets report section’s Can Grow property to Yes• Can Shrink property – set to yes, shrinks the section or

control vertically to avoid blank lines– Setting these properties often involves trial and error.

• design is very important but often it comes down to trying a report, looking at your results, and then making alterations accordingly.

Creating the Self Join Inner (default)

Page 9: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Report Snapshot

• Report snapshot is a file (.snp extension) contains high-fidelity copy of each page preserving two-dimensional layout, graphics, and other embedded objects of the report.– picture of a point-in-time, snapshot does not update as the

data updates. – advantage of snapshot is provide a report to someone

without them having Access installed to view it. (E-mail)• similar to creating a PDF to be used in Acrobat.

Page 10: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Report Snapshot

• If snapshot viewer not installed must install before viewing reports. – book shows you where to find the viewer on the web, also

available on your Office CD• if the CD is necessary, you will be prompted to insert it into your CD

drive.

Page 11: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Report Snapshot First Page of Report

Page 12: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Event Properties

• How Event-driven programming works:– When an action is associated to an Event, that

action does not happen unless the event occurs. If the event never occurs, the action never happens.

– Example the Click of the mouse:• An object is clicked on the screen and

something happens. The click of the mouse is the event which “triggers” the underlying action.

Page 13: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

• Data events - occur when data is entered, deleted, or changed in a form or control. They also occur when the focus moves from one record to another.

• Error and timing events - are used for error-handling and synchronizing data on forms or reports.

• Filter events - occur when you apply or create a filter on a form.

• Focus events - occur when a form or control loses or gains the focus.

Event Properties

Page 14: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

• Keyboard events - occur when you type on a keyboard.• Mouse events - occur in a form or in a control on a form as a

result of a mouse action, such as pressing down or clicking the mouse button.

• Print events - occur when a report is being printed or is being formatted for printing.

• Window events - occur when you open, resize, or close a form or report.

Event Properties

Page 15: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Print Events

• Format – occurs when Access determines what data goes in a report section, but happens before section is formatted for previewing or printing

• NoData – occurs after Access formats a report for printing when report has no data, but before report printed

• Page – occurs after Access formats a page for printing, but before page is printed

• Print – occurs after Access has formatted data in a report section, but before section is printed

• Retreat – occurs when Access must back up past one or more report sections on a page to perform multiple formatting passes– occurs after the section’s Format event, but before Print event– Allows undoing changes made during Format event for section

Page 16: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Converting Macros to VBA Code

• Macros are easier to create, VBA code is executed faster.– VBA code allows you to add code that will handle errors, better

way to automate user interface• Differences between functions and sub procedures

– Functions return a single value• function does not ALWAYS return a value, this type of

function is called a Void function. – sub procedure does not return a value.

• store their code in a standard module – standard module differs from; say a form module, in that it is

not tied to any particular object. (Avoids duplicate code) • Previously, created a form module and the code within that

module applied specifically to that form.

Page 17: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Key Terms

• Function Procedure - A procedure that returns a value, such as the result of a calculation.

• Sub Procedure - A procedure that is a series of VBA statements that performs actions but does not return a value

• Void Function - A function used to do work and not return a value. • Standard Module - Standard modules have general procedures

that are not associated with any specific object in the database and are intended for frequently used procedures that can be run from anywhere within your database. (Prevents duplicate code)

• Form Class Module - A module that is saved as part of a form and contains one or many procedures that apply specifically to that form.

Page 18: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Creating Numbered Lists

• Running Sum property – used to calculate record-by-record totals or group-by-group totals in report– Can specify text box to display a running total

• Can set the range over which to accumulate the values• If Running Sum property set to Over All, it counts the

number in the first group and continues counting all records in each successive group, instead of starting over with each group, value accumulates to end of report

• If Running Sum property set to Over Group, running sum value accumulates until another group encountered

Page 19: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Subreports

• Subreport - is a report that is inserted in another report.• can create individual reports and then combine them into a

single report.• One of the reports will need to be established as the main

report.

• Main Report – can be bound to underlying table, query or SQL statement, or it can be unbound– Unbound main report – can serve as container unrelated

subreports– Bound main report – must contain a field in its record source that

is also a field in its subreport(s).

• Subreports often used to show summary data related to the detail data

Page 20: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Page Numbering

• Page property – specifies current page number when page is being printed

• Pages property – specifies total number of pages in report– Page and Pages properties can be used in an expression,

macro, or VBAExample expression:

=“Page “ & Page & “ of “ & Pages• Report’s Page property is read-write at run time, means it can

be reset at any time by using macro or code as the report prints

Page 21: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

Adding Blank Rows to a Report

• Access does not provide a method to insert a blank row in the middle of a Detail section– Can use VBA code and properties of controls and sections

on report to insert blank rows• To add blank rows to a report, insert a blank unbound text

box (txtSpacer) in detail section below other text boxes, set the Can Grow and Can Shrink properties of txtSpacer text box and the Detail section to Yes

• For blank row to print, txtSpacer needs to contain “ “, causes text box to print, but nothing visible inside it

• Can write VBA code to insert blank row after a certain number of records

Page 22: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

VBA Terminology

• If…Then…Else statement – conditionally executes a group of statements in VBA depending on results of an expression

• Control structure – series of VBA statements that work together as a unit (sequence, selection, iteration)

• VBA statement – is a unit that expresses one kind of action, declaration, or definition in complete syntax

Page 23: Tutorial 5New Perspectives on Microsoft Access 2003 with Visual Basic for Applications Tutorial 5 Creating Complex Reports Reporting on Data in the MovieCam.

Tutorial 5 New Perspectives on Microsoft Access 2003 with Visual Basic for Applications

VBA Terminology

• VBA expression – combination of keywords, operators, variables, and constants that yields a string, number, or object

• Operators – used to perform arithmetic calculations, combine strings, and perform logical operations– Mod Operator – arithmetic operator used to perform

modulo division, divides two numbers and returns only the remainder.


Recommended