Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you...

25
Access 2007 Creating Reports

Transcript of Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you...

Page 1: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Access 2007 Creating Reports

Page 2: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Creating Reports 2

Contents

Creating Reports ....................................................................................................... 3

Create a report with the Report wizard 3 Views 4 Previewing a report 5

Printing a report ....................................................................................................................................................................................... 5 Margins, report size and pagination .......................................................................................................................................................... 5

Creating a user-defined report 6

Editing a Report ....................................................................................................... 7

Viewing a report in Design View 7 Sections ..................................................................................................................................................................................................... 7 Controls .................................................................................................................................................................................................... 7

Changing the look of a report 7 Report and control properties 8

Grouping and Sorting ............................................................................................... 9

Viewing and changing grouping and sorting 9 Additional Group & Sort options .......................................................................................................................................................... 10

Editing grouping and sorting 10

Adding unbound Controls ....................................................................................... 12

Page numbering 12 Date and time 12 Parameters on reports 13 Adding calculated controls 13

Calculated control on Forms .................................................................................................................................................................... 13 Expression syntax .................................................................................................................................................................................. 13 Expression builder .................................................................................................................................................................................. 14 Examples of useful expressions ............................................................................................................................................................... 14

Editing calculated controls 15 Calculated controls on Reports 15

Simple calculations .................................................................................................................................................................................. 15 Aggregate functions ................................................................................................................................................................................. 15

Creating labels in a report ....................................................................................... 17

Numbering items on a Report ................................................................................ 18

Formatting Reports ................................................................................................. 19

Conditional Formatting 19

Adding subreports ................................................................................................... 20

Multiple Column Reports ........................................................................................ 21

Command buttons on forms ................................................................................... 23

Command Button Wizard 23 Command Button Wizard Options ........................................................................................................................................................ 23

Creating a Command Button manually 25

Page 3: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Creating Reports 3

Creating Reports A report is an effective way to present your data in a printed format because you have more control over the appearance of everything on the report. Like Forms, reports are based on tables or queries but can also have additional text, line, images etc. Reports allow you to group data based on specific fields and add summary information such as totals and averages.

Create a report with the Report wizard

Using the Report wizard is the simplest and fastest way to create a report. When you use the Report wizard to create a multiple table report, Access creates an SQL statement behind the report. The SQL statement includes the information about which tables and fields to use. You can also create a query which includes fields from one or more tables and base your report on this. There must be a relationship between the tables in order to create one report from them.

1. From the Create tab, select Report Wizard.

2. Select the table on which you want to base the form on in the Tables/Queries box.

3. Select the table or query on which you want to base your report from the Table/Queries drop-down list. The fields from the table or query will appear in the Available Fields box.

4. In the Available Fields box, select the fields that you want to include in your report and click on the arrow button to move the selected fields to the Selected fields box on the right. Click Next.

5. You can apply Grouping Levels to your report if your wish. Click on the field you want group by and click on the right arrow button. Click Next when you are happy with the layout.

Page 4: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Creating Reports 4

6. You have the option to sort by up to four fields, in either Ascending or Descending order. Select the fields you want to sort on, if necessary, and click Next.

7. Choose a layout for your report and select an appropriate page orientation. Click Next.

8. Select a style for your report. Click Next.

9. At the final step, type in a title for your report and click Finish. The form will open in Print Preview (see below).

10. To close Print Preview and go to the Design View, click on the Close Print Preview button.

Views

Access offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default view which will usually be Report View. You can change this by changing the Default View property of the report.

Note that reports created in Access 2003 or earlier will open in Print Preview by default.

Once you have opened the report you can use the View button on the Home tab to switch between views. You can also use the buttons on the bottom right of the Access window in a similar way.

Page 5: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Creating Reports 5

Previewing a report

To go to Print Preview from another view, select Print Preview from the View button on the Design tab.

Print Preview allows you to view the report as it will be printed, displaying the appropriate data. In Print Preview you only have the Print Preview tab on the ribbon which allows you to change the layout of the report for printing, zoom in and out etc.

When you position the mouse pointer over the page it becomes a magnifying glass. Click once to zoom in, click again to zoom out from the page. Use the navigation bar at the bottom on the screen to view other pages.

To leave Print Preview, click on the Close Print Preview button on the Home tab. If you previously had another view of the report open you will be returned to that view but otherwise the report will be closed.

Printing a report

1. Preview the report as explained above.

2. Use the buttons on the Page Size and Page Layout tab to set margins, change from Portrait to Landscape etc. or use the Page Setup button to set all of these options.

3. Click on Print, enter the appropriate pages and number of copies and click OK.

Margins, report size and pagination

When creating reports in Access, it is important to be aware of the maximum length and width available on each page. Unlike other applications such as Microsoft Word, the margins and page breaks are not shown in Design View. This will depend on the size of the paper you are using and the size of the margins. So for example, if the report is sized for A4 paper with Landscape orientation the page will be 29.7 cm wide. If the margins are 1.5 cm (15 mm) on each side, the available width on each page is just over 26 cm. The length of the report in pages will depend on the paper size and the number of records that need to be displayed. This may of course vary over time if new records are added to the database.

To ensure that you make the best use of the page and/or to reduce the width of a report:

Change the orientation from Portrait to Landscape or vice versa

Increase or reduce the spaces between the controls

Change the font size

Change the margins

Blank pages

If the width of your report is wider than the space available on one page but the part of the report that ‘overflows’ onto a second page width is empty, Access will still create an additional blank page or pages. For example, if you have 1.5 cm margins on an A4 page with Landscape orientation, this gives you about 26 cm width per page. If your report is 27 cm wide but the last 1 cm on the right-hand edge is blank, Access will still give you a blank page. You have to manually resize the area of the report by dragging the border to the desired width

If the page is truly blank, Access will display a warning message indicating that the report width is wider than the page width but that there are no items in the additional space. However, a page may also

Page 6: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Creating Reports 6

appear blank when there is actually a very small part of a control (for example the end of a line) in the ‘blank’ page so this needs to be moved or resized in order for you to be able to reduce the page width.

Creating a user-defined report

The easiest way to create a report is by using the wizard and then customising the report as illustrated above. However, you can also create your own, user-defined report from scratch:

1. Click on the Report Design button on the Create tab.

2. Access will create a blank report with a Detail, Page Header and Page Footer sections.

3. You can now:

Resize the report as appropriate.

Choose a table or query as the Record Source for your report.

Add fields to your report using the Field List.

Move, resize and format field and label controls.

Add unbound controls.

Add grouping and sorting to your report

See Editing a Report on page 7 and Grouping and Sorting on page 9 for more details.

Page 7: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Editing a Report 7

Editing a Report

Viewing a report in Design View

To modify a report you need to open it in Design View where you can make changes to the various sections and controls:

Sections

Like a form, a report consists of sections which are marked out with a grid:

Detail: The main part of the report which contains report controls (see Error! Reference source not found., pError! Bookmark not defined.)

Report Header: Anything placed here will appear at the top of the report.

Report Footer: Anything placed here will appear at the bottom of the report.

Page Header: Anything placed here will appear at the top of each page of the report.

Page Footer: Anything placed here will appear at the bottom of each page of the report.

The report, page headers and footers can be turned on and off from the view menu.

Helpful hint:

Group headers and footers may also be visible if you added Grouping Levels to your report (see Grouping and Sorting on page 9 for more information).

Controls

These are similar to those on a form (see Error! Reference source not found. on page Error! Bookmark not defined. for more details).

Changing the look of a report

Once you have created a report using the wizard you can make simple changes to it in a similar way to making changes to the look of a form. See the following sections of this document for more details:

Change the size of the report (see Error! Reference source not found. on page Error! Bookmark not defined.)

Add report headers and footers (see Error! Reference source not found. on page Error! Bookmark not defined.)

Move and resize controls (see Error! Reference source not found. on page Error! Bookmark not defined.)

Format controls (see Error! Reference source not found. on page Error! Bookmark not defined.)

Change the background colour (see Error! Reference source not found. on page Error! Bookmark not defined.)

Add and remove controls (see Error! Reference source not found. on page Error! Bookmark not defined.)

Additional note: selecting and moving controls on reports

In reports, the field labels are often placed in the Page Header of the report rather than the Detail section. This is so that the label appears once at the top of the page (like a table column heading) rather than being repeated for each record. This separates the label and its associated field control. (see Error!

Page 8: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Editing a Report 8

Reference source not found. on page Error! Bookmark not defined. for details of how this affects moving the label and its field).

Additional note: moving a label to a header

You can add a field to a report from the field list as you would in a form (see Error! Reference source not found. on page Error! Bookmark not defined.). By default, the field control and its label will be added to one section. If the field label should be in a header section (e.g. the page or group header) you will need to move the label:

1. Click and drag the appropriate field from the field list onto the Detail section of the report.

2. Click on a blank area of the form to remove the selection from the field.

3. Select the label only by clicking on its top left-hand corner.

4. Remove the label from the Detail section using the Cut command.

5. Click on a blank area of the header to select it.

6. Use the Paste command to paste the label into the header section.

7. Click and drag the label to the desired position.

Helpful Hint:

If you accidentally cut both the label and the field control, use the Undo command and try again!

Report and control properties

Report and report control properties are viewed in the same way as form and form control properties. See Error! Reference source not found. on page Error! Bookmark not defined. for more details.

Note that you can copy a report and change the Record Source if you want to keep the same format but use a different set of data, just as you would with a form. See Error! Reference source not found. on page Error! Bookmark not defined. for more details.

Page 9: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Grouping and Sorting 9

Grouping and Sorting You can sort the records in a report by up to ten fields. Creating multiple sort levels effectively groups your records by each field. For example, if you sort a report containing doctors by specialism and then by position and then by doctor name, all the doctors of a particular specialism will be grouped together and within each of these groups they will be grouped by position and then within each position they will be sorted in order of doctor name.

In addition, you can create group headers and footers on the report. By placing the field control of that particular field in its group header you can create a heading above each group. So, for example, each specialism will appear as a header with all the doctors who have that specialism listed underneath.

If you create a report using the Report wizard and you choose to add grouping levels, Access will automatically add group headers based on these levels you set. Access will also add whatever sorting order you defined in the wizard. The field controls are automatically listed left to right in the sort order you chose, with any field controls with group headers being placed in their appropriate headers.

Viewing and changing grouping and sorting

1. Open the report in Design View.

2. Click on the Group & Sort button on the Design tab. The Group, Sort and Total pane appears below the report, displaying any existing grouping and sorting:

3. Click on Add a group to add a new Group Header and Footer. In the example below, a Specialism group has been added:

4. When you add a group, a header will be added for the appropriate Field as a group header. Once you have added any groups, you will also need to move the appropriate field from the Detail section into its group header. So, for example, if you add a group which groups on Specialism you should move the Specialism field to the Specialism header on your report.

Fields are sorted in the order they appear in the Group, Sort and Total pane. In the example above, records are sorted first by Specialism and then by DoctorName All doctors with the same specialism (e.g. Cardiac) will appear together and within each specialism they will be sorted by DoctorName. The specialism groups will be in alphabetical order.

Change the sort order

Change the field to group on

Move up and down (to change the order in which sorting and grouping is applied)

Remove a group or sort

Page 10: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Grouping and Sorting 10

Additional Group & Sort options

Group by character(s)

Fields can be grouped on a partial value rather than the whole value in a field. So, for example, grouping could be added to a surname field to group by first letter. To do this, click on the More option and change by entire value to one or more characters.

Keep together

You can decide whether all fields in a particular field group will appear on one page on the report or whether to allow them to split over two pages. In a multiple column report, this also prevents groups splitting across columns. To do this, click on More and then change do not keep group together on one page to your preferred option.

Adding and removing headers and footers

You can choose whether a header or footer is displayed for a specific group. Click on More and change the with a header section and with a footer section options. Footers are not added by default but are useful for adding Totals (see below).

Totals

You can add aggregrate functions (calculations) to groups to make calculations across the whole group. For example you can sum or average the values in a particular field, count values or records or find the minimum or maximum value in a field. To do this, click on the More button and click on the drop-down next to with no totals. A Totals pane will appear:

The appropriate aggregate function will be added as a new calculated control. So for example, in the example above, =Avg([Salary]) will be added to the group footer.

Editing grouping and sorting

Removing Totals

The easiest way to remove unwanted totals is to delete the controls that have been added to the report.

Removing grouping

1. Cut and paste the field control for the grouped field from the Group Header to the Detail section.

2. Change the Group Properties so the Group Header and Group Footer properties are set to No.

The data will still be sorted by the field it was grouped by unless you delete the field from the Sorting and Grouping box.

Changing grouping

You may, for example, wish to change a report so that instead of grouping by Specialism it is grouped by Position:

1. Cut and paste the Specialism Field Control from the Group Header section to the Detail section.

Select a field to add an aggregate function to

Select whether to put it in the header or footer

Select the function you want to use

Add a Grand Total to the report footer

Page 11: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Grouping and Sorting 11

2. Change the field that the Group is grouped on from Specialism to Position This will change the Group Header so that it says Position Header instead of Specialism Header.

3. Cut and paste the Position field Control from the Detail section to the Group Header section.

4. Arrange the controls and their associated labels so Specialism is to the right of b (in other words, swap them around).

5. Reformat the controls appropriately. The easiest way to do this is to use Format Painter to format the Position control like the Specialism one and then copy the formatting from another control in the Detail section to the Specialism one.

Report with specialism group header

Design View

Print Preview

Page 12: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Adding unbound Controls 12

Adding unbound Controls Unbound or calculated controls are not linked or ‘bound’ to a specific field in a table and the result that is displayed in them is not stored anywhere in the database. However, they may use the value in a bound control as part of the ‘expression’ that determines their value. For this reason they may be ‘dynamic’ in that if the values they are based on change, the result of the calculation will also change.

A calculated control uses an expression to obtain its data. On a form, these are calculated and displayed on each individual record. On a report they might be calculated for each record or they might aggregate data for a number of records depending on where they are placed.

Page numbering and date and time controls are also examples of unbound controls. These controls can be added to any section of your report or form but are usually placed in the headers or footers. Once they have been created they can be moved, resized or formatted like any other unbound control.

Page numbering

Page numbering can be added to your forms or reports. Numbering can be positioned in the header or footer. You can insert just the page number, or page number and total number of pages, e.g. 3 of 9.

1. In Form or Report Design view, click on Page Numbers on the Design tab.

2. In the Page Numbers dialog box, select the Format, Position, and Alignment for the page number. For alignment, the following options are available:

Left : adds a text box at the left margin.

Center: adds a text box centred between the left and right margins.

Right: adds a text box at the right margin.

Inside: adds text boxes at the left and right margins. Odd page numbers print on the left and even page numbers print on the right.

Outside: adds text boxes at the left and right margins. Even page numbers print on the left and odd numbers on the right.

3. To show a number on the first page, select the Show Number On First Page check box.

Date and time

Like page numbering, date and time controls can be added to any section of your form or report.

1. In Form or Report Design view, click in the appropriate section of your form or report.

2. Click on Date and Time on the Design tab.

3. In the Date and Time dialog box, tick appropriate boxes to include either date and time or just date or time.

4. Use the options beneath the Date and Time check boxes to select how the date/time appears.

5. Click OK.

Page 13: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Adding unbound Controls 13

Parameters on reports

Parameters can be used to allow the person opening a Report to add unbound text to the Report, for example to add a title or to add their name to the Report.

To create a parameter control, add a text box and in the Control Source property, type text within square brackets that is not a Field Name. When you view the report in Print Preview, Access will prompt you for the value you would like to place in the text box.

For example, if you type [date of Report] in the Control Source this will prompt anyone who runs the Report to enter a date into a dialog box as shown on the right. Any text you type into this dialog box will appear in the text box on your Report.

You can also use this method to add parameters to your Report which are already in a Query on which your Report is based. The user will be prompted for the parameters which will be entered as criteria into the Query and will also appear on the Report itself.

Adding calculated controls

A Calculated Control uses an expression to obtain its data. An expression is a combination of operators such as = and +, Control Names, Functions and constant values (numbers). On a Form, calculated

controls are calculated and displayed on each individual record. On a Report they might be calculated for a specific record or aggregate data for a number of records.

Calculated control on Forms

1. Open the Form on which you want to place the calculated control in Design View.

2. Add a Text box.

3. Click and drag over an area on the Form to draw the box. The Text Box will appear on the form with an accompanying Label.

4. Click into the box and replace the text Unbound with the expression you wish to create Or Type the expression into the Control Source property in the Property Sheet. Or Use the Expression builder to create an expression (see below).

5. Edit the Label caption and/or move or remove the Label as required.

Expression syntax

When creating expressions, observe the following rules:

All expressions should start with an equals = sign.

Round brackets ( ) and mathematical operators Plus +, Minus -, Divide / and Multiply * can be

used in the usual way.

Control Names of Controls on the Form can also be added, enclosed in square brackets. For example, if the form is based on the Table tbl_doctor and there is a Control called Salary on the Form, this Control can be included as: [Salary]

Helpful Hint

If you need more room to type an expression in the Control Source Property box, press Shift+F2 or right-click on the box and select Zoom to open the Zoom Window.

Page 14: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Adding unbound Controls 14

Expression builder

The Expression Builder allows easy access to the names of fields and controls in your database, as well as many of the built-in functions available to you when writing expressions. With the Expression Builder, you can create an expression from scratch, or you can select from some pre-built expressions for displaying page numbers, the current date, and the current date and time.

To access the Expression Builder, click in the Control Source of the calculated control’s text box and click on the Build Button to the right. The Expression Builder dialog box is displayed.

Building an Expression

The upper section of the Expression Builder contains an expression box where you construct your expression. You use the three columns in the lower section of the Expression Builder to locate elements that you can paste into the expression box.

The folders in the lower left pane contain objects in their database (forms, reports, tables etc.) and selecting a specific object (e.g. frm_doctor) allows you to see its associated controls in the central pane.

There are also folders in the left pane containing other useful expressions and functions. For example, DateDiff, which calculates the difference (in years, months, days) between two dates, can be found in the In-built Functions folder within Functions (Date and Time category). The Common Expressions folder contains expressions to add today’s date, the current time, the current page etc. to a form.

Examples of useful expressions

=[Salary] + ([Salary]*0.1) adds 10% to the original salary figure

=Date() displays today's date

=Now() displays today's date or the current time

=[Price]*[Quantity] multiplies a price field with a quantity field

=[Salary]/12 divides a salary by 12

=[Salary]+[Bonus] adds a salary field to a bonus field

=[Income]-[Expenses] subtracts an expense field from an income field

=DateDiff(“d”,[DateEntered],Date()) Finds the number of days (d) difference between the DateEntered Field and Today’s Date.

As you build an expression it appears in the upper section. When you click OK the expression is entered in the Control Source property of the text box.

Click on the plus symbols to expand the tree and see different objects and functions. If you select an object, its controls appear in the middle pane.

You can also click on Constants or Operators to view these options.

Double-click on a control to add it to the expression.

Page 15: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Adding unbound Controls 15

=[FirstName]&" "&[LastName] concatenates the text from two different Controls (i.e.displays the text from two different Controls together in one text box) separated by a space

=IIf([Date_Left]<=Date(),"This employee has left","")

Editing calculated controls Once you have created a calculated Control you can edit its Properties in the Property window. You can add appropriate formatting to your Control using the Format and Decimal Places Properties. For example, a calculated Control based on the Salary field could have a Format Property of Currency and Decimal Places Property of 2.

Calculated controls on Reports

Adding calculated fields to a report is done in exactly the same way as putting calculated controls on Forms as described above. The main difference is that Calculated controls on reports can do either simple or aggregated calculations depending on where they are located.

Simple calculations

When placed in the Detail section, calculations are based on the values within that particular record. For example, if you have a report based on employees displaying their salary in one control and their bonus in another, a calculated control could be created in the Detail section to add these two figures together. Like the other controls in the Detail section, there will be a separate text box for each record (i.e. each employee).

Aggregate functions

When placed in a header or Footer, however, calculated controls can be used to make calculations based on a set of records. To find aggregate values for a group of records place the text box in the Group Footer (to find aggregate values for each group) or in the Report Footer (to find aggregate values for all the records). For example, if a report grouped employees by department, an aggregated calculation could be created to find the average, minimum, maximum, total etc. of salary by placing that control in the group footer. See the examples below for details of how to produce different types of aggregates.

Examples of aggregate functions

A set of expressions are given below. The Field names given in bold are used for examples and can be replaced with your own:

=Count([TelNo]) Counts the number of values in the TelNo Field (note that blanks are not counted)

=Count(*) Counts number of records in a group

=Sum([Salary]) Finds the Sum of salaries

= Avg([Salary]) Finds the Average salary

Other aggregate functions include Min( ) (to find the minimum or lowest value) and Max( ) (to find the maximum or highest value. In the Expression Builder, aggregate functions can be found in the In-built Functions folder within Functions (SQL Aggregate category).

Helpful Hint:

These can be added by using the Totals option on the Group, Sort and Total pane. See

Page 16: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Adding unbound Controls 16

Additional Group & Sort options on page 10 for details.

Page 17: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Creating labels in a report 17

Creating labels in a report The Report wizard can be used to create printer-friendly pages of labels quickly and easily:

1. On the Create tab, click on Labels in the Reports group.

2. Select the appropriate labels from the options provided and click Next.

3. Choose appropriate font formatting for your labels and click Next.

4. Select the fields you wish to include in your labels, adding spaces and using the Enter key to create new lines where necessary. Additional text can be added by typing it in – this text will be repeated on each label. Click Next.

5. Choose which fields you would like to sort by. You can choose multiple fields. In the example below, the labels will be listed by Dept_ID and then within each department by Last_Name and then First_Name. Click Next.

6. Name the report and choose See the labels as they will look printed to open in Print Preview:

Page 18: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Numbering items on a Report 18

Numbering items on a Report A ‘Running Sum’ Control can be added to any section of your Report and it will consecutively number each item. For example, if it is added to the Group section, it will number each Group or if it is added to the Detail section it will number each record. Record numbering can be set to number all records consecutively or to recommence numbering at the start of each new Group.

To create a Running Sum:

1. Use the Text Box drawing tool on the Toolbox to create an unbound Text Box on your Report. A Label and Text Box will be created.

2. Delete the Label.

3. Type =1 into the Control Source box and select Over Group or Over All in the Running Sum box as shown on the right. ‘Over Group’ will restart the numbering at the start of each Group.

Helpful Hint

To add a full stop after each number, add another Text Box as described in 1. and 2. above and place it just to the right of the running sum Text Box. In the Control Source Property, type = ” . ” No spaces should be entered in this expression.

Example

The example below shows a Running Sum followed by a full stop that have been added to the Detail section of a Report and set to create a Running Sum ‘Over Group’ as in the Property Window above.

Running Sum Text Box

Full Stop added

Numbering as seen in Print Preview

Page 19: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Formatting Reports 19

Formatting Reports Once you have created a Report using the Report Wizard you can ‘fine-tune’ it to give it a more polished appearance. As well as adjusting the size and position of the Controls on the Report and adding any additional Unbound Controls (as described above) you may wish to change some of the font formatting to make certain parts of the Report clearer, such as making Header and Footer text bold. You may also wish to do some or all of the following:

Change the alignment of number fields to left-aligned if this would make them look better on the Report.

This can be done by selecting the Field Control and clicking on the Align Left button on the toolbar.

Set the Can Grow Property in the Property Window to Yes for any Controls which might contain more than one line of data. This allows the Control to increase by additional lines so that text can ‘wrap’ onto a new line if necessary.

Set the Repeat Section Property in the Property Window to Yes for any Group Headers. This ensures that if a Group takes up more than one page on your Report the Header will be repeated on additional pages.

Conditional Formatting

Formatting can be applied to a Control which only takes effect in specific circumstances. For example, you can use this to change the font colour if the value in a Number or Date Field is greater or less than a particular number or date or if it falls within a particular range.

To apply conditional formatting:

1. Select the relevant Control you wish to format.

2. From the Format tab select Conditional Formatting.

3. Click on New rule

4. Select the appropriate option in the drop-down lists and type in any values.

5. Use the formatting buttons to select the formatting you wish to apply if the condition is true.

6. Click OK to add the rule.

7. Add additional rules by repeating these steps.

8. Use the Edit Rule and Delete Rule options to change or remove existing rules.

Examples

Field Value Is greater than 40000 (in the Salary Field): formats salaries above £40000

Field Value Is between 1/1/2000 and 31/12/2000 (in the EmployedDate Field): formats doctors employed in the year 2000.

Field Value is equal to “Consultant” or Field Value is equal to “Registrar”(in the Position Field): formats doctors who are Registrars or Consultants. This is achieved by entering two Conditions and applying the same formatting to each (although different formatting could also be used) as below:

Page 20: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Adding subreports 20

Adding subreports Subreports can be added in a similar way to adding Subforms to a Form.

1. Ensure the Use Control Wizards option in the Controls group of the Design tab is switched on.

2. From the Controls group of the Design tab, click the Subform/Subreport button.

3. Choose to either use an existing Form as your Subreport or choose a Table or Query to base it on. If you create a new Subreport it is saved as a Report and can be opened and edited from the Database Window.

Formatting a Subreport

The following formatting changes can help to improve the look of a report with a subreport:

Create a border around a Subreport control to clearly distinguish it from the main Report.

Reduce the height of the Subreport control to a minimum (i.e. drag the lower border of the control up until the control looks like just a ‘line’ in Design View. You should also set the Can Grow property of the Control to Yes. These changes ensure that items on the main Report with no related records in the Subreport will not have a large amount of empty space beneath them and that the Subreport will increase in size according to how many related records there are in the Subreport.

Remove the Subreport Label. If you don’t do this, items on the main Report with no related records in the Subreport will still have a Label appearing beneath them which would be confusing. An alternative would be to edit the actual Subreport to include a heading in the Report Header.

Example

The example below shows a Report based on tbl_doctor with a SubReport showing related records in tbl_patient. The Subreport has a border and its Can Grow property has been set to Yes.

Page 21: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Multiple Column Reports 21

Multiple Column Reports A multiple column Report can be useful when you wish to save space on a Report. Usually, the Report Header and Footer and Page Header and Footer span the full width of the Report while the Group header and footer and Detail section span the width of one column as shown below:

There are two main steps to creating a multiple-column Report:

Re-arrange the Controls on the Report:

1. Create a Report in the normal way.

2. In Design View, move any controls in the Detail section or Group Headers and Footers so that they are within the width of what will be the first column. The example shown above would be created in Design View as below:

Change the Page Setup:

1. On the Page Setup tab, click on the Columns button

2. In the Page Setup dialog box, click the Layout tab.

3. Under Grid Settings, in the Number of Columns box, type the number of columns you want on each page.

4. In the Column Spacing box, type the amount of space you want between the columns.

5. Under Column Size, type the width you want for a column in the Width box, for example 5 cm.

Report Header

Group Header

Detail Section

Report has two12 cm columns so all controls are within the first 12 cms of the Form

Labels are placed in Group Header (Fields are grouped by Specialism).

A Calculated Control to count the number of records in each group in the Group Footer.

Page 22: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Multiple Column Reports 22

6. Under Layout Items, click the Down, Then Across option or the Across, Then Down option.

7. Click OK.

Helpful Hint

It is a good idea to calculate the correct width of the columns before creating the Report. This can be done by calculating the report width available based on the paper size and margins and then splitting that width up into appropriately sized columns . In the above example, the Report is created on A4 paper with Landscape orientation so the whole sheet of paper is 29.7 cm wide. If the margins are 1.5 cm (15 mm) on each side, the Report width can be approximately 26 cm. This means that you can have two 12 cm columns with up to 2 cm spacing between them.

Page 23: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Command buttons on forms 23

Command buttons on forms A Command Button is used on a Form to start an action or a set of actions. For example, you could create a Command Button that opens another Form. A Command Button has an On Click Property which links to the Event Procedure or Macro which will run when the button is clicked.

You can create over thirty different types of command buttons with the Command Button Wizard. When you use the Wizard, Access creates the Button and the Event Procedure for you. Alternatively, you create a Command Button manually and select a Macro from the drop-down list of the OnClick Property to associate the Macro with the button. See Error! Reference source not found. on page Error! Bookmark not defined. for details of how to create Macros.

Command Button Wizard

To create a Command Button using the Command Button Wizard:

1. Open the Form you want to add the button to in Design View.

2. Ensure the Toolbox is displayed and the Control Wizard is turned on.

3. Click on the Command Button button on the Toolbox.

4. Click on the Form where you want to place the button. The Command Button Wizard is displayed on your screen as shown left.

5. Select the relevant Category from the options on the left.

6. Select the required Action from the box on the right and click Next. You may be prompted for further details, such as the name of the Object you wish to open, depending on the Action chosen.

7. In the next dialog box, decide whether you want Text or a Picture on your button.

8. If you selected Text, type in the text you want displayed on your button in the box.

9. If you selected Picture, click on the Browse button and locate the picture you want Or Select one of the Pictures listed in the dialog box. Click on a Picture to see a sample of it on the left in the dialog box.

10. Click Next.

11. In the final box, type in a name for your Command Button.

12. Click Finish.

13. Switch to Form View to try out your new button.

Command Button Wizard Options

Most of the Actions available from the Command Button Wizard are fairly straightforward and could be carried out by the user of the database by using Toolbar buttons, Form Navigation buttons or by opening Database Objects from the Database Window. Adding these Actions to a Command Button can be useful if, for example, you have hidden the Database Window or any toolbars (see Startup Options on page Error! Bookmark not defined. for details) or if you wish to make it easier for the user to carry out a common action quickly and easily.

Page 24: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Command buttons on forms 24

However, the Open Form Action (available under the Form Operations Category) can be particularly useful because it is possible to apply a specific Filter to the records of the Form you are opening depending on the current record in the current Form. For example, if you are in a Form shows patient details with their admissions as a Subform, you could use a button on the admissions Subform which would open the wards form and only show the ward for that particular admission (i.e. the ward that the patient was admitted to).

To do this:

1. Follow the steps 1 to 4 above to create a Command Button using the Wizard.

2. At steps 5 and 6, choose the Form Operations Category and select the Open Form Action from the list.

3. Select the appropriate Form from the list provided and click Next:

4. Select Open the form and find specific data to display and click Next:

5. Select the appropriate Fields from the two Forms that are linked together and click Next:

6. Complete the remaining steps 7 to 13.

Page 25: Access 2007 - University of ExeterAccess offers a number of different views for Reports. When you double-click to open a report from the Navigation Pane it is opened in its default

Command buttons on forms 25

Creating a Command Button manually

1. Ensure that the Toolbox is displayed and the Control Wizard is turned off.

2. Click on the Command Button button on the Toolbox.

3. Click on the Form where you want to place the button.

4. Select the new button you have created and view its Properties.

5. Edit the button by changing the appropriate Properties as listed below:

Property Function

Name Change the name of the button if appropriate

Caption Type the text you wish to appear on the button

Picture Click on the Build Button to the right of the Picture Property and use the Picture Builder to choose from a list of pictures Access provides or click on the Browse button to select one of your own.

On Click Select a Macro from the drop-down list to run it when the Command Button is clicked on in Form View. See Error! Reference source not found. on page Error! Bookmark not defined. for details of how to create Macros.