version 2010 advanced - wwp 2010 advanced course book.pdf · microsoft access 2010 – advanced...

267
MICROSOFT ACCESS VERSION 2010 ADVANCED

Upload: lyhanh

Post on 05-Feb-2018

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

MICROSOFT ACCESS

VERSION 2010

ADVANCED

Page 2: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page i

CONTENTS

LESSON 1 – CONCEPTS OF NORMALISATION......................................................................................1

Database Design ..........................................................................................................................................2

LESSON 2 - ANALYSING TABLES .............................................................................................................4

Introduction ..................................................................................................................................................5

Using The Table Analyser Wizard ............................................................................................................5

Using The Performance Analyzer .............................................................................................................7

Documenting A Database ...........................................................................................................................8

Exercise .......................................................................................................................................................10

LESSON 3 - TRANSFERRING DATA ........................................................................................................11

Introduction ................................................................................................................................................12

Using Data from Another Source ............................................................................................................12

Exchanging Data With Excel ....................................................................................................................15

Using The Linked Table Manager ...........................................................................................................21

Exporting Data ...........................................................................................................................................21

Exercise .......................................................................................................................................................24

LESSON 4 - DATABASE UTILITIES ..........................................................................................................25

Converting Files .........................................................................................................................................26

Adding Security Encryption To A Database (Password Protecting) .................................................27

Compacting And Repairing A Database ................................................................................................29

Backing Up A Database ............................................................................................................................29

Using Name Autocorrect ..........................................................................................................................30

Exercise .......................................................................................................................................................32

LESSON 5 - SPECIAL QUERIES ................................................................................................................33

Join Types In A Query ..............................................................................................................................34

Using The Crosstab Query Wizard .........................................................................................................36

Using The Find Duplicates Query Wizard ............................................................................................37

Using The Unmatched Query Wizard ....................................................................................................38

Exercise .......................................................................................................................................................41

LESSON 6 - CREATING RELATIONSHIPS .............................................................................................42

Introduction ................................................................................................................................................43

Creating A Relationship Between Tables ...............................................................................................46

Setting Referential Integrity .....................................................................................................................48

Adding Cascade Options ..........................................................................................................................49

Viewing Subdatasheets .............................................................................................................................51

Deleting A Relationship ............................................................................................................................53

Exercise .......................................................................................................................................................55

Page 3: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Contents

WWP Training Page ii

LESSON 7 - FORM DESIGN TOOLS AND METHODS ..........................................................................56

Form Headers and Footers .......................................................................................................................57

Setting The Tab Order ...............................................................................................................................59

Creating a Form from Blank.....................................................................................................................61

Creating A PivotTable Or PivotChart View ..........................................................................................63

Filtering a PivotChart or PivotTable View .............................................................................................68

Using AutoCalc in a PivotTable or PivotChart View ...........................................................................68

Hiding and Unhiding Items in a PivotTable View ...............................................................................70

Changing PivotTable and PivotChart View Properties .......................................................................70

Exercise .......................................................................................................................................................72

LESSON 8 - SPECIAL FORM DESIGN TECHNIQUES ..........................................................................74

Automating Forms with Control Wizards .............................................................................................75

Creating a Command Button to Carry Out a Form Action .................................................................75

Creating a Command Button to Find Records on Another Form.......................................................78

Creating Command Buttons to Carry Out Record Navigation/Operation ......................................80

Creating A Combo Box .............................................................................................................................82

Creating A List Box ...................................................................................................................................85

Creating An Option Group ......................................................................................................................86

Adding A Logic Control ...........................................................................................................................89

ActiveX Controls ........................................................................................................................................91

Exercise .......................................................................................................................................................94

LESSON 9 - SPECIAL REPORT DESIGN TECHNIQUES ......................................................................96

Controlling Sections in Report Design View .........................................................................................97

Creating A Calculated Control ................................................................................................................98

Sorting a Report .......................................................................................................................................100

Grouping Data In A Report ....................................................................................................................101

Creating a Summary Calculation for a Group.....................................................................................104

Inserting a Page Break.............................................................................................................................105

Changing The Report Margins ..............................................................................................................107

Creating A Blank Report ........................................................................................................................108

Exercise .....................................................................................................................................................111

LESSON 10 - USING CHARTS ..................................................................................................................113

Creating a Chart .......................................................................................................................................114

Changing The Chart Type ......................................................................................................................117

Formatting Chart Objects .......................................................................................................................118

Exercise .....................................................................................................................................................120

LESSON 11 - USING SUBFORMS/SUBREPORTS .................................................................................121

Creating MainForm/Subform and MainReport/SubReport Arrangements ..................................122

Formatting Main/Sub Form/Report Arrangements..........................................................................136

Page 4: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Contents

WWP Training Page iii

Displaying A Subform/Subreport Total ..............................................................................................140

Exercise .....................................................................................................................................................144

LESSON 12 - WORKING WITH INDEXES .............................................................................................145

Introduction ..............................................................................................................................................146

Creating A Single Field Index ................................................................................................................147

Creating A Multiple Field Index ...........................................................................................................148

Deleting An Index ...................................................................................................................................149

Creating A Multiple Field Primary Key ...............................................................................................149

Exercise .....................................................................................................................................................151

LESSON 13 - WORKING WITH MACROS .............................................................................................152

Introduction to the Macro Designer ......................................................................................................153

Creating A Macro ....................................................................................................................................154

Saving A Macro ........................................................................................................................................158

Using Single Step Mode For Testing A Macro ....................................................................................158

Running A Macro ....................................................................................................................................160

Editing An Existing Macro .....................................................................................................................161

Managing Long Text in Message Boxes ...............................................................................................162

Running A Macro From The Database Tools Tab ...............................................................................164

Running a Macro from the Quick Access Toolbar ..............................................................................164

Exercise .....................................................................................................................................................167

LESSON 14 - FURTHER MACROS ...........................................................................................................169

Introduction ..............................................................................................................................................170

Assigning a Macro To a Form or Report Control Event Property ....................................................173

Assign a Macro To a Form Command Button .....................................................................................174

Creating A Macro Directly From a Form/Report Control Event Property ....................................176

Adding a Simple IF Condition To A Macro .........................................................................................178

Using the Expression Builder to Help Create Conditional Expressions ..........................................180

Adding Advanced IF Conditions to a Macro ......................................................................................182

Creating Submacros ................................................................................................................................186

Handling Errors in a Macro ...................................................................................................................188

Using Groups in Macros .........................................................................................................................191

Creating An Autoexec Macro ................................................................................................................193

Macro Examples .......................................................................................................................................194

Exercise .....................................................................................................................................................197

LESSON 15 - USING SWITCHBOARDS ..................................................................................................200

Introduction ..............................................................................................................................................201

Creating A Switchboard From a Blank Form ......................................................................................201

Using the Switchboard Manager ...........................................................................................................202

Creating a Switchboard in a Database with Overlapping Windows ...............................................205

Page 5: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Contents

WWP Training Page iv

Opening A Switchboard Automatically ...............................................................................................207

Exercise .....................................................................................................................................................209

APPENDIX A - CUSTOMISING THE QUICK ACCESS TOOLBAR AND THE RIBBON ..............211

Adding Commands to the Quick Access Toolbar ...............................................................................212

Customising the Application Ribbon ...................................................................................................214

APPENDIX B - ADVANCED CUSTOMISATION OF THE USER INTERFACE ...............................221

Customising the Ribbon .........................................................................................................................222

Understand the XML Example ..............................................................................................................227

Creating a Custom Shortcut Menu for Use with a Form or Report .................................................230

APPENDIX C - ADDING MACROS TO TABLE EVENTS (DATA MACROS) .................................234

Creating Data and Named Macros .......................................................................................................235

Managing Data and Named Macros .....................................................................................................236

APPENDIX D - USING ACCESS AND THE INTERNET......................................................................239

Updating Data Via Email .......................................................................................................................240

Exporting Database Objects To HTML .................................................................................................244

Importing Or Linking To A Html File ..................................................................................................246

Importing from Sharepoint ...................................................................................................................248

APPENDIX E – ADVANCED ACCESS SECURITY ...............................................................................250

Creating A Digital Signature ..................................................................................................................251

Digitally Signing And Packaging A Database .....................................................................................252

Using The Trust Center ...........................................................................................................................255

Locking A Database ................................................................................................................................257

Locking Database Records .....................................................................................................................258

INDEX ...........................................................................................................................................................259

Page 6: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 1

LESSON 1 – CONCEPTS OF NORMALISATION

In this lesson, you will learn how to:

Normalise Data

Page 7: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 1 – Normalisation

WWP Training Page 2

DATABASE DESIGN

Discussion

The theory of database design includes standards called normal forms. The process of arranging your data into the standards is called Normalisation or Normalising data. By normalising your database, you eliminate redundant data and organise your tables so that managing data and future changes to the structure of the database is easier.

By normalising your database you split larger tables into smaller tables which are more manageable and easier to maintain. To work with the related data you must then reconnect the tables via relationships between common fields.

Data normalisation is not specific to Access, but is part of the database design process. There are five normal forms; each addresses specific problems and each assumes the requirements of the preceding form have been satisfied.

First Normal Form

A Table is in the First Normal Form when each field contains the smallest meaningful value and the table does not contain repeating groups of fields.

Tables that are not in the first normal form usually have fields containing data that can be broken down into smaller meaningful parts eg. placing a complete name into one field instead of splitting it into first and last names. They also contain repeating groups of fields which list the same category of data in multiple fields. This can be corrected by creating separate tables for each of related values.

Second Normal Form

The Second Normal Form applies only to tables with a multiple field primary key. In these tables any non key fields should relate to the entire primary key. In other words, any non key fields should be a fact about the entire primary key.

Tables that are not in the second normal form usually have repeating values in a field due to the fact that the field does not relate entirely to the primary key. If a field’s value depends only on part of the primary key it should be removed and placed in a separate table.

Third Normal Form

The third normal form applies only to tables with a single field primary key. In these tables each non key field should be a fact about the primary key. That is a non key field should not be a fact about another non key field.

Tables that are not in the third normal form usually have repeating values in a field due to the fact that the field does not relate to the primary key. If a field’s value does not describe the primary key it should be removed and placed in a separate table.

Fourth Normal Form

A Table is in the Fourth Normal Form when there are no independent one-to-many relationships between what should be the primary key and non key fields.

Tables not in the fourth normal form usually contain blanks in non key fields and duplicate values in the field you want to set as the primary key. The usual reason for this is the table has been based on two different subjects. Separate the data into two new tables each about one specific topic.

Page 8: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 1 – Normalisation

WWP Training Page 3

Fifth Normal Form

A Database is in the fifth normal form when the tables are broken down into the smallest possible tables to eliminate redundant non key fields. Usually, tables that are not in this form contain repeating values of data in the non key fields.

Putting a database in this form allows you to control database integrity. Because each piece of non key data normally only appears once in the data base it is relatively easy to update the data.

Junction Tables

A normalised database will sometimes not contain common fields which allow you to create relationships between tables. To overcome this, create a table, sometimes called a junction table, which contains the fields which can link the tables. For example if you have a table which has a list of employee numbers and names and a table which contains project numbers and descriptions, you need to create a Junction table which contains the fields for employee number and project number and use this to assign employees to projects.

Tip

When designing tables there are three basic rules that you can follow to ensure a good database design.

Make each table only about one specific subject.

Each non key field should be a fact about the entire primary key.

Each field should contain the smallest meaningful data value.

Page 9: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 4

LESSON 2 - ANALYSING TABLES

In this lesson, you will learn how to:

Analyse a table

Use the Table Analyzer Wizard

Use the Performance Analyzer

Use the Documenter

Page 10: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 2 – Analysing Tables

WWP Training Page 5

INTRODUCTION

Discussion

When you create or analyse a table, you should look at its structure to determine the efficiency of its design. If the same information appears in multiple records, the table can probably be split into two related tables. Splitting a table is more efficient because the tables are then smaller and, as a result, easier to manage. In addition, information will only need to be entered one time. Smaller tables also reduce the chance of making data entry errors.

If you feel that a table may need to be split, you can use the Table Analyser Wizard to analyse it for you and suggest which fields should be in each table. The Table Analyser Wizard can also create the correct table relationships.

When the Table Analyser Wizard splits a table, it creates the necessary relationships in the resulting tables. These relationships allow data from all the tables to be used in queries, forms, and reports.

USING THE TABLE ANALYSER WIZARD

Discussion

The Table Analyser Wizard looks at a table to determine if it contains duplicated information. If the Table Analyser Wizard determines that a table has a lot of duplicated data, it splits the table, creating new tables and leaving the original table intact.

When the Wizard is open, you select the table you want to analyse. On subsequent pages, you indicate whether you want the wizard to decide how to split the table or whether you want to do it yourself. If you allow the wizard to split the table, the recommended tables and the relationships between them appear. You can then move fields between tables or even drag fields to create new tables. Each piece of information should be stored in only one location, and each table should contain only data that refers to a single subject.

Once the fields have been put into the correct tables, you can set the primary keys. In order to be related properly, each table must have a primary key, and the primary key must be a field that uniquely identifies each record. Therefore, a primary key field cannot contain duplicate data. Access will generate unique fields, if necessary.

Procedure

1. Select the Database Tools tab.

2. Click the Analyze Table command.

Page 11: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 2 – Analysing Tables

WWP Training Page 6

Step 1 of the Table Analyzer Wizard

3. Read the first two explanatory pages, clicking Next button after each.

4. In Step 3, select the table you want analysed.

5. Click the option for the Wizard to decide regarding field locations.

6. Click the Next button.

7. Rename the tables.

8. Click the Next button.

9. Choose whether to specify primary key(s).

10. Click the Next button.

11. Set corrections if necessary.

12. Click the Next button.

13. Choose whether to accept the query.

14. Click the Finish button.

NB: After finishing the Wizard, Access takes you to the “About the Table Analyzer Wizard” page on the Microsoft website.

Page 12: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 2 – Analysing Tables

WWP Training Page 7

USING THE PERFORMANCE ANALYZER

Discussion

The Performance Analyser analyses the efficiency of your database in order to optimise its performance.

The Performance Analyser window contains a page for each available object type in Access, as well as a Current Database page and an All Object Types page. The Current Database page allows you to analyse features that are not objects, such as relationships. You can analyse a single object or multiple objects on different pages. If you are analysing different types of objects, the All Object Types page allows you to view all database objects in one location.

The results of the performance analysis appear in the Analysis Results box. The results are categorized as a Recommendation, Suggestion, or Idea. The Analysis Notes box provides additional information about the selected result.

You can use the Optimise button to have Access perform the action suggested in a Recommendation or Suggestion; you must manually perform the action for an Idea. After you have selected the Optimise button, the Performance Analyser marks the action as Fixed.

Procedure

1. To optimize database performance, first open the database you want to optimize.

2. Click the Database Tools tab.

Page 13: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 2 – Analysing Tables

WWP Training Page 8

3. In the Analyze group, click the Analyze Performance button.

4. In the Performance Analyzer, select the object(s) you want analysed.

5. Click OK.

6. Click each item and review the analysis notes.

7. Press and hold down the [Ctrl] key while clicking the suggested optimizations.

8. Click the Optimize button.

9. Click the Close button.

DOCUMENTING A DATABASE

Discussion

A complex database may include many tables, queries, forms and relationships. One of the Access analysis tools is the documenter which analyses the database and can print a report of all details of the database.

Procedure

1. Select the Database Tools tab.

2. In the Analyze group, click the Database Documenter command.

3. In the Documenter dialog box, click the items on each tab that you want documented.

4. Click the Options… button.

5. In the Print Table Definition dialog box, click the desired options.

6. Click OK.

Page 14: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 2 – Analysing Tables

WWP Training Page 9

7. Click OK.

8. The Documenter will display a print preview of the report.

Table Documenter report

Page 15: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 2 – Analysing Tables

WWP Training Page 10

EXERCISE

Analysing Tables

1. Open Train1.

2. Open the Table Analyser Wizard (Database Tools > Analyse Table).

3. Select Next as needed and then select the Project List table.

4. Click Next.

5. Allow the wizard to decide how to split the table.

6. Click Next.

7. Rename Table1 to Project and Table2 to Client.

8. Drag the State field from the Project field list below the City field in the Client field list.

9. Click Next.

10. Set the Client ID field as the primary key in the Client table.

11. Click Next.

12. Do not have the Table Analyser Wizard create a query.

13. Select Finish.

14. View the tables and then close them.

15. Restore the Navigation Pane.

16. Analyse the performance of the Client and Payment tables (Database Tools > Analyse Performance).

17. Notice that the analysis result does not fit the data; changing the Zip field to a long integer field would not allow for zip codes with leading zeroes, such as 08054.

18. Close the Performance Analyser.

19. Close the database file.

Page 16: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 11

LESSON 3 - TRANSFERRING DATA

In this lesson, you will learn how to:

Use data from another source

Link data to an external source

Exchange data with Excel

Use the Linked Table Manager

Export data

Page 17: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 12

INTRODUCTION

Discussion

You can import data from one or more external data sources. The external data source can be another Access database, a database created in a different program such as Excel, ASCII text, or an HTML data table.

When you import data from a spreadsheet, another type of database, or ASCII text, a wizard opens to step you through the process. The format of the data in the external data source does not change. You can use Access to add, edit, or delete the data.

If the external data source is an Access database, you can also import database objects such as queries, reports, and forms. This option allows you to copy a query from one database to another and modify it as necessary, rather than creating a new one. In addition, you can easily copy standard reports and forms between databases.

USING DATA FROM ANOTHER SOURCE

Discussion

In an Access database, you can either import or link to data in an external data source. Importing will create a static copy of the data as it stands at the time of importing. Linking will create a shortcut to the data that is automatically updated each time an object using the data is opened.

You can import from of link to an external data source, such as another Access database or a database created in a different program such as Excel. You can also link to HTML data tables on a network server or on the Internet.

Linking tables is useful when you want to share data on a network. If you link to a table on a network, the link ensures that the data you are viewing is always the latest available.

When you link to an external data source, the format of the data in the data source does not change, although you can use Access to add, edit, or delete the data.

A linked table displays a special icon in the Database window. A table linked to another Access database has an arrow to the left of the icon. A table linked to a source created in a different program displays an arrow and the initials of the source program.

Examples of link icons.

From left to right: Access table; Excel worksheet: Text file

When you delete a linked table, you are deleting the icon and the link to the source table, not the source table itself.

Procedure

Copying an object from another Access database

1. Select the External Data tab.

2. In the Import & Link group, click the Access command.

Page 18: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 13

3. In the File name: box, type or locate (using the Browse… button) the database that you want to import data from.

4. Select the Import tables, queries, forms, reports, macros and modules into the current database option.

5. Click OK.

6. In the Import Objects dialog box, click the table(s) you wish to import.

7. If necessary, open the other tabs and select more items to import.

8. Click OK.

9. Tick the Save import steps check box if you intend carrying out an identical import again in the future.

Page 19: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 14

10. Click Close.

Linking data into a database from another data source

1. Select the External Data tab.

2. In the Import & Link group, click the button for the application/file that you are linking to (eg. Access, Excel, Text File, etc.)

3. In the File name: box, type or locate (using the Browse… button) the source for the linked data. The appearance of this window will vary depending on the application/file that you are linking to. In some cases, you are given the option of adding the linked data to an existing table. The example screenshots below show linking from an Access database (left) and linking to a Text File (right).

4. Select the relevant option for linking to the data source.

5. Click OK.

6. The next window will again vary depending on the data source that you are linking to. The example screenshots below show linking to an Access table (left) and to a Text File (right).

7. Select relevant options and settings as necessary.

8. Finally, tick the Save import steps check box if you intend carrying out an identical link again in the future.

9. Click Close.

Page 20: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 15

10. Click OK to the message confirming that the data has been linked. The linked data displays in the Navigation Pane with a special “link” icon.

EXCHANGING DATA WITH EXCEL

Discussion - Importing Data From Excel

If you have data in an Excel workbook, you can use the information in an Access database. You can import or link all the data from a workbook or the specified data from a named range. When you import or link data, Access usually creates a new table for the information.

Procedure

1. Click the External Data tab.

2. In the Import & Link group, click the Excel command.

Page 21: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 16

3. Click the Browse… button and locate and select the Excel workbook containing the data you want to import.

4. Click the Open button.

5. Choose from the three options as to whether you want import, append, or link.

6. Click OK.

7. Select the worksheet containing the data you want to import or, change the option to Show Named Ranges and select the range that you want to import.

8. Click Next.

Page 22: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 17

9. Specify whether the data has column headings.

10. Click Next.

11. Specify options, if necessary, for the first field (ie. Field Name: Indexed: Data Type: Do not import field (Skip)).

12. Click the thin, grey heading for the next column.

13. Repeat step 11.

14. Continue setting options for all columns, if necessary.

15. Click Finish.

Page 23: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 18

16. Tick the Save import steps check box if you anticipate importing the table again. You can then repeat the process without having to go through all the steps of the Import Wizard.

17. If step 16 has been actioned, click Save import otherwise, click Close. The imported table is added to the Navigation Pane under tables.

Tip

To successfully import Excel data, ensure that the data table starts in cell A1 of the worksheet. If this is not possible, for example, there is a title or blank rows at the top of the worksheet, name the data range in Excel and import it using the Show Named Ranges option.

Tip

If you have saved the import steps, you can re-import the same data using the Saved Imports command – External Data tab > Import & Link group

. The Saved Imports dialog box can also be used to delete and rename the saved import(s). You can add a reminder to Outlook to run the import on a particular date or in a recurring pattern. The Outlook task includes a command button to run the import.

Page 24: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 19

Discussion - Exporting Data to Excel

Access table data can easily be converted into an Excel worksheet for analysis. Once the data has been transferred, Excel can be used to analyse or chart the data. The resulting data can then be imported back into Access.

Procedure

1. Click the External Data tab.

2. In the Export group, click the Excel button.

3. Click the Browse… button to specify a destination for the exported data.

4. In the File Save dialog box, select the location for the new workbook and name it.

5. Click Save.

Page 25: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 20

6. Click the File format: drop down list.

7. Select the Excel format to export the data as.

8. Tick, if required, the Export data with formatting and layout check box.

9. Tick the Open destination file after export operation is complete check box, if required. This check box will only activate if step 8 above has been actioned.

10. Click the OK button. If step 9 has been actioned, Excel will launch and the data displayed. Quit Excel.

11. Tick the Save export steps check box if you anticipate importing the table again. You can then repeat the process without having to go through all the previous steps again.

12. If step 11 has been actioned, click Save export otherwise click Close.

Tip

If you have saved the export steps, you can re-export the same data using the

Saved Exports command – External Data tab > Export group . The Saved Exports dialog box can also be used to delete and rename the saved export(s). You can also add a reminder to Outlook to run the export on a particular date or in a recurring pattern. The Outlook task includes a command button to run the import.

Page 26: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 21

USING THE LINKED TABLE MANAGER

Discussion

You can use the Linked Table Manager to view, refresh, or correct the file name and/or path of a linked table. If the structure of a linked table changes, for example, you can use the Linked Table Manager to refresh the link.

In addition, if a linked table is moved to a different location, you can use the Linked Table Manager to correct the path and re-establish the link. The Linked Table Manager does not physically move database files or tables; it only refreshes or corrects the link information.

If you change the name of a table after it has been linked, the Linked Table Manager will not be able to refresh the links. In this case, you must delete the link and create a new one.

Procedure

1. Select the External Data tab.

2. Click the Linked Table Manager command in the Import & Link group.

3. In the Linked Table Manager dialog box, select the link(s) you want to refresh.

4. Click the OK button.

Or

1. To change the path to a linked table, click the Always Prompt for New Location

option.

2. Check the tables whose links are to be changed.

3. Click the OK button.

EXPORTING DATA

Discussion

You can export data and database objects to a variety of supported databases, programs, and file formats. For example, you can export data to another program (such as dBASE or Excel),

Page 27: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 22

to ASCII text, or to an HTML data table. You can also export most database objects from a Microsoft Access database to another Access database. The process of exporting data and database objects is very similar in functionality to copying and pasting.

When exporting database objects to another database, you can only export one object at a time. If you need to export multiple objects to a database, it may be more efficient to open the database to which you want to export and import the objects.

When you export an object to another database, it might be helpful to export all related objects to ensure full functionality. For example, a report is usually based on a query, and a query is based on one or more tables.

The following table lists some of the data formats to which you can export:

Application Notes

Microsoft Access database Can export as Access 2010 only. See page 26 for converting Access databases to previous versions

Excel All versions back to Excel 5 (Office 4.2/4.3).

SharePoint List

Word Rich Text Format (RTF) Creates a “compatibility mode” Word document and shows the data as a Word table.

PDF or XPS

Text File

If exporting as unformatted text (recommended), a Wizard appears from which you can select the delimiter to use.

XML

ODBC database

Usually requires assistance from your IT department in order for you to access the required server. There may be security implications.

HTML Export as a webpage.

dBASE Versions 5, III and IV

Procedure

1. Display the Tables list in the Navigation Pane.

2. Right click the table you want to export.

3. Hold the mouse pointer over the Export command.

Page 28: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 23

4. On the shortcut menu, click the type of file you want to export to.

5. The next step will vary depending on what type of file format you wish to export as; in most cases, you will need to specify a location for the exported file. In the File

name: box, type or Browse… to the location for your exported file and name it.

6. Select additional preferences under Specify export options.

7. Click OK.

8. Depending on the file type chosen, you may have to carry out other steps to complete the export. Follow any additional instructions, Wizards, or dialog boxes offered.

9. Upon returning to the Export window select, if desired, to save the export steps.

10. Click the Close button.

Tip

You can also export data in different files type by selecting the appropriate command in the Export group of the External Data tab.

The procedure is then the same as described from step 5 above.

Page 29: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 3 – Transferring Data

WWP Training Page 24

EXERCISE

Transferring Data

1. Open Train2.

2. Import the Sales by Rep 2 query from the Train17x Access database in the student folder. Do not save the import steps.

3. Import with a link, the Sales table from the Train17x database.

4. Open the Linked Table Manager and update the link to the Types table. Correct its path to student data files folder.

5. Click OK as necessary and close the Linked Table Manager.

6. Close Train09X.

7. Open TrainV97.

8. Click No to upgrading the database to the new format. Notice how, when the database opens, most of the commands on the Ribbon are unavailable.

9. Close Trainv97.

10. Re-open Trainv97.

11. Click Yes to upgrading it. Notice how when the database opens, commands are now enabled.

12. Close Trainv97.

13. Open Trainv03. Notice that it opens without a need to upgrade it to the latest format. This would also be the case with databases created in versions 2000 and 2002(XP).

14. Use the File tab, Save & Publish command to upgrade it to the Access 2010 format with the name Trainv2010.

15. Click OK to the error warning; this is not critical to a successful conversion.

16. Click OK to the confirmation message.

17. Export the Order Details table to Excel with formatting and layout and specify that you want to open the Excel file after export is complete. Leave the file name as suggested (Order Details.xlsx) but store it in the student data folder.

18. View the data in Excel and then exit Excel without saving, if prompted.

19. Do not save the export steps and close the export window.

20. Close the database.

Page 30: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 25

LESSON 4 - DATABASE UTILITIES

In this lesson, you will learn how to:

Convert files

Encrypt a database

Compact and repair a database

Back up a database

Use Name AutoCorrect

Page 31: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 4 – Database Utilities

WWP Training Page 26

CONVERTING FILES

Discussion

When you open an Access database that was created in a version prior to Access 2007 (eg. Access 2002(XP), Access 2000, Access 97, Access 7.0 (95), Access V2/V1), Access 2010 holds the file in compatibility mode where it disables features which cannot be displayed or converted well by previous versions. The database stays in the original file format until you convert it to the Access 2010 format.

You can convert an Access database of earlier format, though you may want to keep the database in the earlier version and just run it in 2010. This is important where the database is used by more than one user, not all of whom have Access 2010.

You can also convert an Access 2010 format back to an earlier format providing the Access 2010 .accdb database does not contain any of the new features.

If opening an Access 97 or Access 95 database, the Database Enhancement dialog box will be displayed, indicating the file must be upgraded in order be able to use the latest features.

Procedure (for files created in Access 97, Access 2000, Access 2002 or Access 2003)

1. First, open your database:

2. Select the File tab.

3. At the left, click Save & Publish.

4. Click Save Database As under File types.

5. Click Access Database under Save Database as.

6. In the Save As dialog box, navigate to the location to store your converted file and enter a name for it in the File name: box.

7. Click Save. A copy of the database is created in Access 2010 format.

8. If, necessary, click OK to the confirmation message.

NB: If converting an older format to 2010, the message informs you that the file has been saved in the Access 2007 format which is fully compatible with 2010.

Page 32: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 4 – Database Utilities

WWP Training Page 27

ADDING SECURITY ENCRYPTION TO A DATABASE

(PASSWORD PROTECTING)

Discussion

File encryption is security you can apply to a database which scrambles your password to protect your file from unauthorised people from opening the file. The password protection takes effect the next time you open that database file.

Before you can encrypt a database file in Access, you need to open the database in Exclusive mode in order that the database can be encrypted without any outside connection. This can be done when you open the file or by using the Advanced pane of Access Options. Renaming a database when you encrypt or decrypt it keeps the original database intact.

Procedure

Adding an encryption password

1. Open the database you intend to encrypt in Exclusive mode as follows:

2. Click the File tab.

3. Select Open.

4. Navigate to the location of the file that you want to encrypt and select it from the list.

5. Click the drop down arrow to the right of the Open button.

6. Select Open Exclusive.

7. Click the File tab.

8. Select Info, if necessary.

9. Click the Encrypt with Password button.

Page 33: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 4 – Database Utilities

WWP Training Page 28

10. In the Set Database Password box enter, and confirm, the password.

11. Click OK.

12. When the file has been closed, it will only open if the correct password is entered.

Removing an encryption password

1. Open the encrypted database file in Exclusive mode (see previous procedure).

2. Select the File tab.

3. Select Info, if necessary.

4. Click the Decrypt Database command .

5. In the Unset Database Password box, enter the password.

6. Click the OK button.

Page 34: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 4 – Database Utilities

WWP Training Page 29

COMPACTING AND REPAIRING A DATABASE

Discussion

When you delete tables and other objects in a database, the database size on the disk does not necessarily decrease. Access provides a utility that compacts (defragments) the database, thereby releasing storage space.

You can compact an open database by clicking on the Office button, moving the cursor to the Manage item and choosing Compact and repair Database.

Procedure

1. Open the database that you want to compact and repair..

2. Select the File tab.

3. Select Info, if necessary.

4. Click the Compact & Repair Database button.

BACKING UP A DATABASE

Discussion

It is important to back up your database on a regular basis. Most companies have a backup process to ensure that all data is saved at least once a day; consequently, all databases shared on a company network server are backed up daily as well.

Your database may be saved to the hard drive of a personal computer, however, most databases are too large to fit on a floppy disk. In this case, you should back up your hard drive regularly by saving it to another drive or to removable media. Backing up your hard drive ensures that all data, queries, forms, and reports in your database are saved. As a result, you can recover your database if something were to happen to it.

Procedure

1. Open the database that you want to backup.

Page 35: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 4 – Database Utilities

WWP Training Page 30

2. Select the File tab.

3. At the left, click Save & Publish.

4. Click Save Database As under File types.

5. Click Back Up Database under Save Database As - Advanced..

6. In the Save As dialog box, specify a name and location for the backup copy or, accept the default name.

7. Click the Save button.

USING NAME AUTOCORRECT

Discussion

The Name AutoCorrect feature automatically fixes inconsistencies that can occur when you rename tables, forms, reports, queries, fields, or other controls in an Access database.

The group offers three options which help fix common side effects that occur when you make changes in an object via a user interface.

Access stores the identifier for each object and tracks any naming information. When access notices an object has been changed since the last Name AutoCorrect action, it runs it again for all items in that object.

Although this feature is activated by default in Access 2010, it was turned off in pre-Access 2000 versions. As a result, if you open a database that was originally created in an older version of Access (even if it has been converted to 2010), the Name AutoCorrect options may not be active.

Procedure

1. To check that Name AutoCorrect is active, first click the File tab.

2. Click the Options button.

3. Click Current Database at the left.

Page 36: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 4 – Database Utilities

WWP Training Page 31

4. Under Name AutoCorrect Options, select all options.

5. Click OK.

Page 37: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 4 – Database Utilities

WWP Training Page 32

EXERCISE

Database Tools

1. Open Train3 exclusively.

2. Encrypt the database using the password secure. Close the database.

3. Open Train3 normally (not exclusively). Notice that you must enter the password.

4. Close Train3 and then re-open it exclusively.

5. Remove the encryption password protection.

6. Close the database.

7. Re-open Train3 normally (not exclusively). Notice that you no longer need to enter the password.

8. Open Train2.

9. Check that all Name AutoCorrect options are enabled (File > Options > Current

Database).

10. Open the Reps table in Design View.

11. Change the name of the LAST_NAME field to LastN and the name of the FIRST_NAME field to FIRSTN.

12. Close the Reps table saving the changes.

13. Open the Reps form in Design View. Notice that, although the label in the Form Header area has not changed, the control source in the Detail area has been corrected to LastN.

14. Close the Reps form design view.

15. Compact and repair Train2.

16. Make a backup of it using the default name.

17. Close Train2.

Page 38: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 33

LESSON 5 - SPECIAL QUERIES

In this lesson, you will learn how to:

Change join types in a query

Use the Crosstab Query Wizard

Use the Find Duplicates Query Wizard

Use the Unmatched Query Wizard

Page 39: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 34

JOIN TYPES IN A QUERY

Discussion

As was described in the previous topic, there must be valid joins between multiple tables in order for accurate and relevant data to be extracted to a dynaset.

The join type is also important. The default type is an inner join, where records are only included in the dynaset if there is matching data in the join fields of both tables. You can, however, create an outer join, where all the records from the one table appear, even if there is no matching data in the other table.

To specify the join type, you need to open the Join Properties dialog box.

There are three type of join available:

Type Description Notes

1 Only include rows where the joined fields from both tables are equal.

This is the default inner join.

2

Include ALL rows from <<first table>> and only those records from <<second table>> where the joined fields are equal.

This is an outer join.

Assume that <<first table>> is a table of customers and <<second table>> a table of orders.

You have added to the query grid the Customer Name field from the customer table and the Order ID field from the Orders table.

The resulting dynaset would show ALL the customers' names but in cases where a customer has not got any related orders in the Orders table, it will leave a blank.

This could be useful to identify customers in your database who haven’t placed any orders for your products.

3

Include ALL rows from <<second table>> and only those records from <<first table>> where the joined fields are equal.

This is also an outer join.

Using the same tables and fields as in type 2 above, the resulting dynaset would show ALL the Order IDs but in cases where an order ID has not got a related customer name, it will leave a blank.

Page 40: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 35

This could be useful to identify orders which do not have a recognisable customer due to input error or because the customer records have been inadvertently deleted or lost.

In the outer join extract below, it is possible to see that B&B Sporting Goods, Champs and The Complete Athlete have no order numbers. It is safe to assume, therefore, that they have not purchased any products. This would have not been possible to see with an inner join because the three shops names would not have appeared in the query.

Procedure

1. To join tables in a query, first open the query in Design view.

2. Drag the desired join field from one field list to the matching field in a second field list.

3. Double-click the middle segment of the join line.

4. Select the join type you require.

5. Click the OK button.

6. The arrow head indicates the direction of the join.

7. View the Query.

6

Page 41: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 36

Tables joined with an outer join. Direction of arrow indicates that

ALL records will be shown from the Customers table

USING THE CROSSTAB QUERY WIZARD

Discussion

Crosstab queries are used to group and summarise information in a spreadsheet format. Crosstab queries make it easier to read and analyse selected data.

You must have three fields in a crosstab query. The values in the first field appear as row headings in the resultant spreadsheet, the values in the second field appear as column headings, and the calculation is performed on the values in the third field.

A crosstab query can display, for example, products sold (row headings) by sales representative (column headings); the number of products sold by each sales representative would appear at the intersection of the corresponding row and column. Crosstab queries can also involve other functions such as sum, count, and average.

Values in a crosstab query cannot be change in order to change the source data.

A Crosstab query

Row groupings

Column groupings

Totals at the crosstab (ie. intersection of row and column)

Page 42: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 37

Procedure

1. Select the Create tab.

2. In the Other group, click the Query Wizard button .

3. In the New Query box, select the Crosstab Query Wizard option.

4. Click OK.

5. From the list, select the table/query that contains the records you want to retrieve.

6. Click the Next button.

7. From the Available Fields: list, add the field you want to use as row headings to the Selected Fields: list.

8. Click the Next button.

9. Select the field you want for column headings.

10. Click the Next button.

11. In the Fields: list, click on the field you want to calculate.

12. In the Functions: list, click the required function.

13. Click the Next button.

14. Enter a name for the query and click Finish.

USING THE FIND DUPLICATES QUERY WIZARD

Discussion

You can use a Find Duplicates Query Wizard to find duplicate records in a table. For instance, there may be identical records stored in a table, when only one record is necessary. The Find Duplicates Query Wizard will locate and display records in which the specified field has the same values.

Page 43: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 38

A Find Duplicates query

Procedure

1. Select the Create tab.

2. In the Other group, click the Query Wizard button .

3. In the New Query dialog box, click the Find Duplicates Query Wizard item.

4. Click OK.

5. Select the table or query you want to use for the query.

6. Click the Next button.

7. Add the desired fields to the Duplicate-value fields: list.

8. Click the Next button.

9. Add any other required fields to the Additional query fields: list.

10. Click the Next button.

11. Enter a name for the query.

12. Click Finish.

Running the query displays any duplicate entry fields as defined in step 7 above.

USING THE UNMATCHED QUERY WIZARD

Discussion

The Find Unmatched Query Wizard allows you to locate and display records in one table for which there is no match in a related table. For example, locating from a customer table, those

Page 44: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 39

who have not placed any orders. This has the same effect as creating an outer join (see page 34).

As was described in the Adding a Table to a Query section of this manual (see page Error!

Bookmark not defined.), there must be valid joins between multiple tables in order for accurate and relevant data to be extracted to a dynaset.

An Unmatched Query – customers with no OrdNum

have not placed any orders

Procedure

1. Select the Create tab.

2. In the Other group, click the Query Wizard button .

3. In the New Query dialog box, click the Find Unmatched Query Wizard item.

4. Click the OK button.

5. In the first dialog box, select the table/query whose records you want to display.

6. Click the Next button.

7. Select the table which contains the related records.

8. Click the Next button.

9. If necessary, specify the joining field.

10. Choose the field from each list.

11. Click the button to join them.

12. Click the Next button.

13. Choose which fields from the Available fields: list to display in the query.

14. Click the Next button.

15. Enter a name for the query.

Page 45: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 40

16. Click the Finish button.

Page 46: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 5 – Special Queries

WWP Training Page 41

EXERCISE

Designing Advanced Queries

1. Open Train4.

2. Start a new query in Design View.

3. Add the Trainer and Project tables.

4. Add the Initials, Project ID and Start Date Fields.

5. View the query and observe the cross product result (375 records).

6. Return to Design View.

7. Create a join between the Initials field in the Trainer field list and the Trainer

Initials field in the Project field list.

8. Run the query and observe the results (25 records).

9. Return to the design view.

10. Change the join type to include all the records from the Trainer table.

11. Run the query and observe the results. Which trainers have not run any projects?

12. Close the query saving it with the name Join.

13. Open Train5.

14. Use the Query Wizard to create a crosstab query from the existing Sales by Rep query:

a. Use the Client ID field for the row headings.

b. Use the Sales Rep field for the column headings.

c. Have the calculated value be the Sum of the Total Sales field.

d. Name the query Total Sales by Sales Rep.

e. Select the option to view the query and click Finish.

f. After you have viewed the recordset, close the query.

15. Use the Query Wizard to create a Find Duplicates Query to locate any duplicate records in the Client table.

a. Select the Client Name, Address, and City fields as possible duplicate-value fields.

b. Do not select any additional fields to show in the query results.

c. Name the query Find Duplicate Clients.

d. Select the option to view the results and click Finish. Notice that two duplicate records are found.

e. Close the query.

16. Use the Query Wizard to create a Find Unmatched Query that finds any projects in the Project table that have no record of payment in the Payment table.

a. Select the Project ID field as the matching field for the two tables, if necessary.

b. Have the Client ID, Course Name, and End Date fields also display in the query.

c. Name the query No Record of Payment.

d. Select the option to view the results and click Finish. Notice that five records are found.

e. Close the query and then close the database.

Page 47: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 42

LESSON 6 - CREATING RELATIONSHIPS

In this lesson, you will learn how to:

Use related tables

Create a relationship between tables

Set referential integrity

Use cascade options

View subdatasheets

Delete a relationship

Page 48: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 43

INTRODUCTION

Discussion

Good database design often requires the use of multiple tables in order to avoid the unnecessary entering of repetitive data.

For example, in a database that stores sales information, it makes little sense having just one table and having to enter the full name, address, telephone number, etc. of a customer every time they place an order; the table would look something like the one below.

This may be acceptable to someone who has been used to working with spreadsheets, but it is not good database practice.

The solution is to have two tables, one containing just customer information (names, addresses, etc.) and another storing just orders information (order numbers, dates, etc.).

There has to be a way, however, of “relating” the tables to one another and this is done via a common field. In the example above this would be the customer ID, hence we get the following:

Customer details table Orders table

When entering an order for a customer, there is now no need to repeat each time the customer’s full name, address, etc.; you just enter the customer ID. If you then want to know the customer names and addresses for each order, you create a query using the two tables joined via the customer ID field. If a new customer is signed up, they are added to the customer details table with a suitable ID.

Common field

Page 49: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 44

Microsoft Access does not require you to create formal relationships between tables to make use of the vast majority of its features. The ability to match data between tables can be achieved with manual “joins” in queries and many other Access features give you the opportunity of matching fields between tables (eg. subforms and subreports) without having to create relationships first.

Furthermore, Access makes a good attempt at joining (or matching) tables automatically. For example, if two tables are added to a query, Access will join the tables via what it thinks is the common/related field if the following rules apply:

Field name in both tables is identical;

Data type is the same (exception being AutoNumber);

One of the fields is a primary key.

There are advantages, however, to creating formal relationships between tables. These are:

Clarifies (where there are many tables) the structure of the database and how the tables interact.

Negates the possibility of errors occurring when making manual or automatic joins.

Enables use of subdatasheets in tables.

Enables use of “referential integrity” to eliminate the possibility of entering unmatched data between tables.

Enables use of “cascade” options to facilitate updating and deleting data.

A relationship between two tables is created in the Relationships window by clicking and dragging between the related fields of the two tables. Access then opens the Edit

Relationships window where you can just click the Create button to form a simple relationship (sufficient for items a), b) and c) above) or, select the Enforce Referential Integrity check box and/or the cascade option check boxes to form a more “advanced” relationship.

If you select the Enforce Referential Integrity option in the Edit Relationship dialog box and click Create, Access will analyse the two tables and identify which to make the “primary” (or “parent”) table and which to make the “foreign” (or “child”) table.

The primary table is determined in two ways:

a) If in one of the tables (let’s call it Table A) the common field is also the primary key field and in the other table (let’s call it Table B) it is not, Access will make Table A the primary table and Table B the foreign table. This is known as a one-to-many relationship because for each record in the primary table, entries in the common field must be unique (occur only once) whereas in the foreign table they may occur many times. Access clarifies this one-to-many relationship by adding a 1 next to the primary table and an infinity symbol

(∞ ) next to the many table.

Page 50: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 45

One-to-many relationship

Furthermore, referential integrity will prevent you making a data entry in the foreign table field if there is no equivalent entry in the primary table field. The following error message will appear.

b) If in both tables the common field is the primary field, Access will look at the direction that you clicked and dragged and make the table where you started from the primary table and the one where you released the mouse button the foreign table. This known as a one-to-one relationship. Access clarified this one-to-one relationship by adding a 1 next to both tables.

One-to-one relationship

Unlike a one-to-many relationship where the primary table has the number 1 next to it, the primary table cannot be readily identified in a one-to-one relationship. By double clicking the link line between the two tables to open the Edit Relationship dialog box, it is possible to determine the primary table at the left of the list.

Identifying the primary table in a one-to-one relationship

Foreign table

Primary table

Page 51: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 46

In the screenshot above, referential integrity will prevent you making an entry into the RepId field of the tblRepsPersonal if a corresponding value is not already in the RepID field of the tblRepsGeneral.

CREATING A RELATIONSHIP BETWEEN TABLES

Discussion

The Relationships window displays a graphic representation of database relationships and allows you to create relationships between tables. You drag field lists in the Relationships window to reposition and resize them as necessary. In addition, any field name that is also a primary key is bolded in the corresponding field list and has a small, gold, key icon at its left

.

Relationship window with Show Table dialog box displayed

You can add tables to the Relationships window for additional joins. For example, if the Relationships window displays only two related tables and you need to access information from a third table, you can easily add the required table to the Relationships window and then create the join.

You can select multiple tables in the Show Table dialog box by holding the [Ctrl] key as you click each table. Selecting Add adds all the selected tables to the Relationships window.

The Show Table dialog box opens automatically if no tables have been added to the Relationships window.

Access will allow you to create a simple relationship between two completely unrelated fields but little will be achieved by doing so! Always, ensure that there is a logical link between the two related fields. A good understanding of the database’s purpose and design is essential.

Page 52: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 47

Relationships between three tables

Procedure

1. Select the Database Tools tab.

2. Click the Relationships command in the Show/Hide group .

3. If necessary, click the Show Table command in the Design tab under Relationship Tools.

4. Select the first table you want to create a relationship with.

5. Click the Add button.

6. Select the second table you want to create a relationship with.

7. Click the Add button.

8. Add further tables as required.

9. Click the Close button.

10. Click and drag from either of the common fields to the other.

11. In the Edit Relationships dialog box, click the Create button.

12. Repeat steps 11 & 12 for any further relationships between these and/or other tables.

13. Close the Relationships window.

14. In the Message box, click the Yes button.

Page 53: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 48

SETTING REFERENTIAL INTEGRITY

Discussion

When you create a relationship between two tables, you can set referential integrity. Referential integrity is a built-in set of rules Access uses to make sure that the relationship is valid. Referential integrity can also prevent accidental deletion or editing of data. In order to use referential integrity, the following conditions must be true:

the related field in one table must be its primary key;

the related fields in both tables must have the same data type; and

both tables must belong to the same database.

When you set referential integrity, you must observe the following three rules:

you cannot enter data in the join field in the "many" table that does not have a match in the join field in the "one" table;

you cannot delete records from the "one" table if there are matching records in the "many" table;

you cannot edit primary key values if related records exist.

Some of the error messages displayed if referential integrity rules are contravened are shown below.

Attempting to enforce referential integrity where there exists data in the

foreign table field that is not in the related primary table field

Attempting to enforce referential integrity where the related field

in the primary table is not a primary key

Page 54: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 49

Attempting to enforce referential integrity between

incompatible field types

If you want to perform any of the changes listed above, however, and still maintain referential integrity, you can select the Cascade Update Related Fields and Cascade Delete

Related Records options in the Edit Relationships dialog box. If either or both of these options are selected, Access automatically makes the necessary changes to related tables to maintain referential integrity. It is recommended that these two options be selected only after careful consideration, since the changes cannot be undone.

When referential integrity is enforced, Access displays symbols above the join line to indicate the type of relationship, one-to-one or one-to-many. The number 1 above a join line indicates

“one”, and the mathematical symbol for infinity (∞) indicates “many.”

Attempting to enter data in a foreign table where there is no

corresponding data in the related primary table field

Procedure

1. Select the Database Tools tab.

2. Click the Relationships command in the Show/Hide group .

3. Click the Edit Relationships button in the Tools group (or double-click on the join line between the two tables whose referential integrity you want to establish).

4. In the Edit Relationships dialog box, select the Enforce Referential Integrity option.

5. Click the OK button.

ADDING CASCADE OPTIONS

Discussion

You might encounter a situation in which you have a valid need to change the value on the "one" side of a relationship. In such a case, you need Access to automatically update all of the effected rows as part of a single operation. That way, the update is completed in full so that your database is not left in an inconsistent state — with some rows updated and some not. Access helps you avoid this problem by supporting the Cascade Update Related Fields option. When you enforce referential integrity and choose the Cascade Update Related Fields option, and you then update a primary key, Access automatically updates all fields that reference the primary key.

Page 55: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 50

You might also need to delete a row and all related records — for instance, a shipper record and all related orders for that shipper. For this reason, Access supports the Cascade Delete

Related Records option. When you enforce referential integrity and choose the Cascade Delete Related Records option, Access automatically deletes all records that reference the primary key when you delete the record that contains the primary key.

Procedure

1. Select the Database Tools tab.

2. Click the Relationships command in the Show/Hide group . If the Show

Table dialog box appears, click Close.

3. Select the Design tab under Relationship Tools.

4. Click All Relationships in the Relationships group. All tables that have relationships are displayed, showing relationship lines.

5. Click the relationship line for the relationship that you want to change. The relationship line appears thicker when it is selected.

6. Double-click the relationship line.

7. Tick the Enforce Referential Integrity check box, if necessary.

8. Select either the Cascade Update Related Fields or Cascade Delete Related Records check box, or select both.

9. Click OK.

Tip If the primary key is an AutoNumber field, selecting the Cascade Update Related Fields check box will have no effect, because you cannot change the value in an AutoNumber field.

Page 56: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 51

VIEWING SUBDATASHEETS

Discussion

Subdatasheets are datasheets nested in the primary table and display the data in the related foreign tables; it rather like being able to see data from two tables at the same time.

When you create a relationship between two tables, Access automatically creates

subdatasheets. When you open the primary table, a column containing expand symbols appears at the left of the table next to each record. Clicking the expand symbol displays a subdatasheet of data from the foreign table.

Table displaying a subdatasheet for related records (one-to-many relationship)

If the primary table has relationships with more than one table, when you click the expand symbol, you are prompted for which table you want to see a datasheet for. Upon selecting the table, Access should automatically identify the related field and populate the Link Child Fields: and Link Master Fields: boxes.

It is not necessary to have a relationship between tables in order to view subdatasheets. If there is a valid joining field between two tables, you can open the primary table and select the Subdatasheet command in the Records group of the Home tab.

Record in primary table

Related records in foreign table

Related records in

Expand buttons for other primary records

Page 57: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 52

This command opens the dialog box shown above and you can select the table that you want to be the source for the subdatasheet and, if necessary, select the appropriate linking fields. When you click OK, Access will offer to create a relationship between the tables but it is not necessary to click Yes for the feature to work.

In addition to viewing data, you can edit data right in the subdatasheet; the edited data is saved back to the table in which it is stored.

Procedure (viewing datasheets)

1. To display subdatasheets, first open the primary table that has a relationship with another.

2. Click the expand symbol next to the record you want to see a subdatasheet for.

3. If available, click an expand button next to a record in the subdatasheet to drill down further into the data.

4. Click the collapse symbol(s) next to any expanded record(s) to close any open subdatasheets.

5. Close the table.

Procedure (changing the subdatasheet source table)

1. Open the primary table for which you to want to change the subdatasheet.

2. Select the Home tab.

3. Click the More command in the Records group.

4. Hold the mouse pointer over the Subdatasheet item.

5. Click Subdatasheet….

Page 58: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 53

6. Select the table or query that you want as the source for the subdatasheet.

7. If necessary, in the Link Child Fields: and the Link Master Fields: drop lists, select the linking field from each table.

8. Click OK.

Tip

You can use the More > Subdatasheet side menu to quickly expand or collapse all the subdatasheets for a table, or remove a subdatasheet form a table.

DELETING A RELATIONSHIP

Discussion

Deleting a relationship line removes the relationship between two tables. You may want to delete a join line if you no longer need to relate the tables or you want to create a different relationship.

You must select a relationship line before you can delete it. You must click the middle segment of a relationship line in order to select it; clicking the beginning or ending segment does not select the relationship line. You can also delete a relationship line by right-clicking its middle segment and selecting the Delete command.

Page 59: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 54

Procedure

1. Select the Database Tools tab.

2. Click the Relationships command in the Relationships group.

3. Click the middle of the relationship line that you wish to delete.

4. Press the [Delete] key.

5. Click Yes to the warning message.

Or

1. Right click the relationship line that you want to delete.

2. Click Delete .

3. Click Yes to the warning message.

4. In all cases, close the Relationships window.

5. Respond to saving the layout, if prompted. This will only appear if you have added, removed or repositioned tables.

Page 60: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 6 – Creating Relationships

WWP Training Page 55

EXERCISE

Creating Relationships

1. Open Train6.

2. Open the Relationships window.

3. Add the Client and Project tables to the Relationships window.

4. Create a relationship between the Client ID field in the Client table and the Client

ID field in the Project table; set referential integrity for the relationship.

5. Add the Trainer table to the Relationships window.

6. Create a relationship between the Trainer Initials field in the Project table and the

Initials field in the Trainer table; set referential integrity for the relationship.

7. Close the Relationships window and save the changes.

8. Open the Client table and view the subdatasheet for the CONCORD client. Then, collapse the subdatasheet and close the Client table.

9. Open the Relationships window and print a relationship report (Tools group).

10. Close the relationship report window without saving changes.

11. In the Relationships window, delete the relationship line between the Project and Trainer tables and remove the Trainer field list, since it is no longer related to any tables. Then, close the Relationships window and save the changes.

12. Close the database file.

Page 61: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 56

LESSON 7 - FORM DESIGN TOOLS AND METHODS

In this lesson, you will learn how to:

Work with form headers and footers

Set the tab order for controls

Create a form from blank

Create a PivotTable or PivotChart view

Manage a PivotTable or PivotChart view

Page 62: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 57

FORM HEADERS AND FOOTERS

Discussion

You can create or customise a form in Form Design view. A form has three basic sections into which you can add “controls” to display the required information: Detail, Form

Header/Footer and Page Header/Footer.

If the form is/was created from new in Access 2010, the form header and form footer sections will appear by default. If, however, you are opening a form in Design View that was created in a previous version of Access (prior to 2007) the form header and footer sections may not appear and if required, will have to be added. A form’s page header and footer will not usually display by default and if required, will need to be added.

Furthermore, the appearance and layout of a form’s headers and footers will vary depending on which version of Access the form was originally created in. In the case of Access 2010 or Access 2007 there also will be a slight difference depending on whether the form was created using the Form Wizard or by clicking the Create > Form command in a Layout. Some examples are given below:

From created in Access 2010 (or 2007) using the Create > Form command (Design View)

From created in Access 2010 (or 2007) using the From Wizard command (Design View)

Page 63: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 58

From created in Access 2003 (Design View)

The Form Header and Form Footer sections display at the top and bottom of a form. They remain stationary when viewing the forms and navigating through them. They can be useful for displaying titles or instructions you want visible on the form at all times. If you print the form, these sections appear at the top of the first page only and at the bottom of the last page only. You can also place controls, including images, labels, and fields in the form header or footer.

The Page Header and Page Footer sections display in Design view at the top and bottom of the form and below/above the Form Header and Footer sections. They do not appear when viewing the form on screen but are used in cases where you may wish to print the forms and have information at the top and bottom of each page. Like the form header and footer, they can contain images, lines, and text, or any other controls you want consistently printed at the top and/or bottom of every page.

When you enable the display of either the page or form header/footer section, both the header and the footer appear. You can drag the header and footer sections to resize them.

Printed forms showing form header/footer and page header/footer

Form Header

Page Header

Page Footer Page Footer

Form Footer

Page Header

Page 64: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 59

Procedure

To display Form and/or Page Headers and Footers if not currently visible

1. Open the required form in Design View.

2. Right click the Detail section of the form.

3. Select the required header(s) and footer(s) in the shortcut menu.

4. Add controls and formatting as desired to the header/footer section(s).

5. Save the form design.

SETTING THE TAB ORDER

Discussion

The tab order determines the order in which form fields and controls are selected when you press the [Tab] key during data entry. The default tab order is the order in which the fields or controls were added to the form.

If you have added, rearranged, or deleted fields or controls, the tab order may not be suitable for data entry. You can choose to have Access automatically rearrange the tab order to reflect the order of the fields on the form. The fields are then accessed from left to right across each row.

You can, however, adjust the tab order manually if you wish to select the fields and controls in an irregular order to meet the needs of your forms.

Procedure

To set the tab order automatically

1. Open the form you want to set the tab order in Design view.

2. Select the Design tab under Form Design Tools tab.

3. In the Tools group, click the Tab Order button .

4. In the Tab Order dialog box, click the Auto Order button.

Page 65: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 60

5. Click OK.

To set the tab order manually

1. Open the form whose tab order is to be changed in Design View.

2. Click the Tab Order button in the Control Layout group .

3. In the Tab Order dialog box, click the record selector to the left of the field you want to move.

4. Point to the highlighted fold and drag the field to the new position; a thin grey line appears to indicate the position.

Page 66: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 61

5. Click OK. he tab order will now be changed when the form is opened in Form view.

Tip

You can also set the tab order manually by entering a number in the Tab Index property (Other tab in the Property Sheet) for each control. The first control to have the focus will be 1, number 2 will be the control that the focus moves to upon pressing the tab key, 3 will be the next, etc…

CREATING A FORM FROM BLANK

Discussion

You can create a form from scratch in Design View. For example, if a form does not currently exist for a particular table or query, you can create one using the fields in the selected table or query. You can then determine the design of the form by adding fields, control, and options.

Procedure

1. Select the Create tab.

2. In the forms group, click the Blank Form button.

3. The blank form is displayed in Layout view together with the Field List.

4. If necessary, click the Show all tables link in the Field List .

5. Click the expand button at the left of the table on which you want to base the form.

Page 67: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 62

6. Drag fields from the Field List onto the blank form where you want to place them to create the form; Layout View will automatically arrange them as a columnar table.

7. Format and/or restructure the table as desired. Switch to Design View if preferred.

8. Save the form.

9. Enter a name for the new form.

10. Click OK.

Page 68: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 63

CREATING A PIVOTTABLE OR PIVOTCHART VIEW

Discussion

You can create a PivotTable or PivotChart view as a form for any table, query, form or report in a database using the More Forms command. Before using the command, the object that you want the PivotTable or PivotChart based on must be selected in the Navigation Pane.

In the case of forms and reports, the PivotTable or PivotChart form is created from the fields contained in their underlying table or query. In all cases, the resulting PivotTable or PivotChart View can be saved and viewed as a separate form.

In PivotTable View, you can group and total large amounts of data into a summarised form.

This is achieved by creating headings in columns and/or rows for all the unique values in a field and adding a calculation at the intersection of each column and/or row.

In the picture below, a PivotTable View is summarising the number of orders taken by reps from different customers. Each rep is shown in a column and each customer is shown in a row; a count of the orders taken is shown at the intersection of each column and row.

Reps

Customers Total sales

made

Page 69: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 64

In similar fashion to a PivotTable View, a PivotChart View allows you to display data in groups and totals but in a graphical environment as opposed to a data table. In the picture below, each rep is shown as an item along the x (category) axis, each country that the reps sell in is shown as a series, and the total value of sales made is shown against the y (value) axis.

You design a PivotTable or PivotChart view by dragging fields from the Field List to drop areas in the PivotTable or PivotChart view workspace. As an alternative to dragging fields, you can also select the desired field in the Field List, select the desired drop area from the bottom of the Field List, and then use the Add to button to add the field to that field.

Dragging and dropping a field to group it by row

Clicking and dragging a field to the PivotChart Category (x-axis) box

Page 70: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 65

In the Field List, fields are listed below a corresponding fieldset. When you expand the fieldset, the individual fields are displayed. Field names become bold when they are added to the view workspace.

Once the table or chart is designed, fields can be moved, added, or deleted as desired. In addition, you can apply formatting to the items in PivotTable or PivotChart to enhance its appearance. You can use options in the Property Sheet to apply formatting and the AutoCalc to change the summary calculation. In more advanced cases, you can create additional fields in the PivotTable of PivotChart for more calculations.

Note: Although the data in a PivotTable or a PivotChart is updated every time you close and re-open it, it does not automatically update if the underlying data is edited while the PivotTable or PivotChart is open. In this case you must click the Refresh Pivot command in the Data group under PivotTable/PivotChart Tools.

,

Tip

You can also create a PivotTable or a PivotChart from a table or query by first opening the table or query that you want to base the Pivot on, and selecting PivotTable View or PivotChart View in the View command on the Home tab.

This method does not create the PivotTable or PivotChart as a separate form but stores it with its underlying table. The Pivot can be viewed or edited whenever the table or query is open by selecting PivotChart View or PivotTable View in the View command on the Home tab

Procedure

To create a PivotTable View

1. Select in the Navigation Pane, the object that you wish to base the PivotTable on.

2. Click the Create tab.

3. In the Forms group, click the More Forms command.

Page 71: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 66

4. From the menu, select PivotTable.

5. Click on the PivotTable workspace to activate it and display the PivotTable Field List. If necessary, click the Field List command in the Design tab under PivotTable Tools.

6. Click and drag the required field item from the PivotTable Field List to the Drop Row

Fields Here box.

7. Similarly, click and drag the required fields to the appropriate Filter, Column, and Total or Detail boxes.

NB: It is not necessary to add items to ALL the PivotTable drop boxes; as a minimum, it is only necessary to have fields in the Row OR Column boxes and in the Total or

Details box.

8. Close the PivotTable View.

9. In the Save As dialog box, enter a name, and click OK.

To create a PivotChart View

1. Select in the Navigation Pane, the object that you wish to base the PivotChart on.

2. Click the Create tab.

3. In the Forms group, click the More Forms command.

Page 72: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 67

4. From the menu, select PivotChart.

5. Click on the PivotChart workspace to activate it and display the Chart Field List. If necessary, click the Field List command in the Design tab under PivotTable Tools.

6. Click and drag the required field item from the Chart Field List to the Drop Category

Fields Here box.

7. Similarly, click and drag the required fields to the appropriate Filter, Series, and Total

or Detail boxes.

NB: It is not necessary to add items to ALL the PivotChart drop boxes; as a minimum, it is only necessary to have fields in the Series OR Categories boxes and in the Data box.

8. Close the PivotChart View.

9. In the Save As dialog box, enter a name, and click OK.

Tip

You can remove fields from a PivotTable or PivotChart View by selecting the field on the PivotTable or PivotChart and pressing [Del] on the keyboard.

On a PivotTable, you can select the field and click the Remove Field

command in the Design tab under PivotTable Tools.

In both PivotTable and PivotChart Views, you can remove a field by right-clicking it in the Field List and clicking Delete.

Page 73: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 68

FILTERING A PIVOTCHART OR PIVOTTABLE VIEW

Discussion

PivotTable and PivotChart filters allow you to extract from the underlying data specific items only. You can drag any field to the filter area and the view will initially display all the items in the field. When you select an item from the filter box, only the data relating to that single item appears in the view.

Filtering a PivotChart View Filtering a PivotTable View

Procedure

1. To filter the data in a PivotTable or PivotChart, click the drop-down arrow in the Filter box and check/uncheck the item(s) to display/hide.

2. Click OK.

USING AUTOCALC IN A PIVOTTABLE OR PIVOTCHART

VIEW

Discussion

When adding a field to the Totals or Details box on a PivotTable, Access initially shows the detail for each group. In itself, this can be useful but you can also use the AutoCalc command to select an aggregate function to perform on the detail.

Page 74: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 69

AutoCalc options applied to a numeric field AutoCalc options applied to a non-numeric field

The functions available will vary depending on the data type for the field in the Totals or Details box. If the field is numeric, AutoCal will contain:

Sum

Count

Min

Max

Average

Standard Deviation

Variance

Standard Deviation Population

Variance Population

If the field is non-numeric , AutoCalc will only offer the Count aggregate function.

You can add as many aggregate functions as you wish to the detail field for example, you may wish to see a Sum and a Count of sales made.

Tip

It is not normally necessary to specify an AutoCalc option in a PivotChart because Access will automatically use SUM if the field added to the Data drop zone is numeric and COUNT if it is non-numeric. You can, however, use the same techniques described above to change the aggregate function. For example, you may wish to change the default SUM function to AVERAGE.

Procedure

1. Click anywhere on the Detail field in the PivotTable.

2. Select the Design tab under PivotTable Tools.

3. Click AutoCalc in the Tools group.

4. Select the required aggregate function from the menu.

Page 75: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 70

HIDING AND UNHIDING ITEMS IN A PIVOTTABLE VIEW

Discussion

When you use the AutoCalc command to add an aggregate function to the Detail of a PivotTable, the detail remains visible. This can make it difficult to focus on and compare the totals, especially if there is much detail for each group.

It is advisable, therefore, to hide the detail to create a clearer and more succinct result. The detail can always be made visible again, if required.

PivotTable View showing detail and totals PivotTable View showing totals only

Procedure

1. Click one of the Detail headings.

2. Select the Design tab under PivotTable Tools.

3. Click the Hide Details command in the Show/Hide group.

4. To replace the detail, click the Show Details command in the Show/Hide group.

CHANGING PIVOTTABLE AND PIVOTCHART VIEW

PROPERTIES

Discussion

General formatting of PivotTable and PivotChart Views (eg. fonts, alignments and colours) can be achieved by selecting the item to format and using the commands in the Text Formatting group on the Home tab.

Page 76: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 71

You may find, however, that certain commands are not available (eg. number formatting) and you will have to open the Property Sheet to access for the required command to control the appearance or behaviour of a PivotTable or PivotChart items.

The Property Sheet contents and commands will vary greatly depending on whether you are working on a PivotTable or a PivotChart. Settings and options available will also vary depending on the item selected on the PivotTable or PivotChart.

Property Sheet for a PivotTable Totals and Details area

Property Sheet for a PivotChart Plot Area

Procedure

1. Click on the field, area or item on the PivotTable or PivotChart that you want to see and edit the properties for.

2. Select the Design tab under PivotTable / PivotChart Tools.

3. Click Property Sheet in the Tools group.

4. Select/change settings and options as desired.

5. Click the window Close button when finished.

Page 77: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 72

EXERCISE

Form Design Tools and Methods

1. Open Train7.

2. Open to view the Payment Form.

3. Press [Tab] as necessary to view the tab order.

4. Open the form in Design View.

5. Open the Tab Order dialog box and set the tab order automatically.

6. Click OK on the Tab Order dialog box.

7. View the form and press [Tab] as necessary to view the tab order.

8. Return to Form Design View and open the Tab Order dialog box.

9. Create a custom tab order by moving the Payment Date controls below the Amount Paid controls. Remember to drag and drop from the row selector (the grey button at the left of each row).

10. Click OK on the Tab Order dialog box.

11. View the form and press [Tab] as necessary to view the tab order.

12. Return to Form Design View

13. Display the form footer (drag down at the bottom of the form to create a space).

14. Add a label containing your name at the left of the form footer.

15. Display the form header/footer.

16. Hide the page header (drag it up from the bottom to close the space).

17. Add an automatic date and time to the bottom right of the page footer (Form

Design Tools > Design tab > Header/Footer group). Access will initially add this to the top of the form design and you will have to move it down.

18. Select the File tab.

19. Click Print > Print Preview. Notice the page footer; the page footer/area can only be viewed in Print Preview or when creating hard copy.

20. Close the form and save it.

21. Open Train8.

22. Open the Payment table.

23. Select the Home tab.

24. Click the View command and select PivotTable View.

25. Create a PivotTable using:

a. Project ID in rows.

b. Months in columns (Hint: Open the Payment Date By Month group in the field list and select Months).

c. Amount Paid in the detail area.

d. Credit Rating in the filter area.

26. Add an aggregate Sum for each Project ID item (Hint: click any cell containing data in the Detail area and select Sum from the AutoCalc command under PivotTable Tools).

27. Hide the details to show just totals for each month (Hint: select the Month field and click Hide Details in the Show/Hide group of the PivotTable Tools Ribbon).

28. Filter data for Credit Rating A only.

Page 78: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 7 – Form Design Tools and Methods

WWP Training Page 73

29. Close the PivotTable View without saving any changes.

30. Close the database.

Page 79: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 74

LESSON 8 - SPECIAL FORM DESIGN TECHNIQUES

In this lesson, you will learn how to:

Activate the Control Wizards

Create command buttons on a form

Create a combo box

Create a list box

Create an option group

Add a logic control

Work with an ActiveX Control

Page 80: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 75

AUTOMATING FORMS WITH CONTROL WIZARDS

Discussion

By using the Control Wizards, automated controls can be more easily created on a form. For example, a set of option buttons can be set up on a form to enable the user to make a choice rather than having to type in the information, a list box could be added to a form to assist in selecting the correct data or a command button could be set up to enable easier use of the form or that when clicked, will display a separate form showing additional information about the currently displayed record.

If you select the Control Wizards button before you create a command button, Access provides you with easy steps to create the control.

Although normally activated by default, the Control Wizards may have been deactivated for the purpose of creating controls manually or, by accident. To ensure that Access assists you to create special controls, the Control Wizards must be activated.

Procedure

1. Open the required form in Design View or Layout View.

2. Select the Design tab under Form Design (Layout) Tools on the Ribbon.

3. Click the More button on the bottom right corner of the Controls group.

4. Click the Form Wizards command .

CREATING A COMMAND BUTTON TO CARRY OUT A FORM

ACTION

Discussion

By using the Control Wizards, a command button can be set to open a form when clicked. The form can be opened for viewing or printing. You can also specify whether you would like to open the form to view all records, or open it to view just specific data. An action can thus be carried out on a form, without having to return to the navigation pane.

Page 81: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 76

Example of command buttons in form Design View

Same form as above in Form View

Procedure (add a command button to open a form)

1. Open the required form in Design View. Although it is possible to carry out this procedure in Layout View, it is easier to position and size the control without the layout feature.

2. Click on the form and press Ctrl A to select all the controls; select the Arrange tab under Form Design Tools and click the Remove Layout command (if active) in the Table group.

NB: If the Remove Layout command is greyed out, it is because the form is not in a layout and you can proceed to the next step.

Page 82: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 77

3. Ensure the Control Wizards command is active.

4. In the Controls group, click the Button command .

5. Click in the form where you want to insert the command button.

6. In the Command Button Wizard select Form Operations in the Categories: list box.

7. In the Actions: list, select Open Form.

8. Click Next.

9. In the next step of the Wizard, select the form you want to open.

10. Click Next.

11. Select the Open the form and show all the records option.

12. Click Next.

13. Enter text for the button or specify a picture.

Page 83: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 78

14. Click Next.

15. Provide a name for the button (Optional). This name will only be necessary if you wish to identify the button later for additional programming purposes.

16. Click Finish.

CREATING A COMMAND BUTTON TO FIND RECORDS ON

ANOTHER FORM By using the Control Wizards, a command button can be set on a form that opens another form showing records from a related table. For example, when viewing a record for a particular customer, you can click a command button that will open another form displaying records of orders placed by that customer.

Procedure

1. Open the required form in Design view. Although it is possible to carry out this procedure in Layout View, it is easier to position and size the control without the layout feature.

Page 84: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 79

2. Click on the form and press Ctrl A to select all the controls; select the Arrange tab under Form Design Tools and click the Remove Layout command (if active) in the Table group.

NB: If the Remove Layout command is greyed out, it is because the form is not in a layout and you can proceed to the next step.

3. Ensure the Control Wizards command in the Controls group is active.

4. In the Controls group, click the Button command .

5. Click in the form where you want to insert the command button.

6. In the Command Button Wizard select Form Operations in the Categories: list box.

7. In the Actions: list, select Open Form.

8. Click Next.

9. In the next step of the Wizard, select the form you want to open.

10. Click Next.

11. Select the Open the form and find specific data to display option.

12. Click Next.

Page 85: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 80

13. Select in the list boxes, the field that relates the two tables.

14. Click the button in-between the list boxes. Ensure the Matching Fields: box correctly shows the related fields.

15. Click Next.

16. Enter text for the button or specify a picture.

17. Click Next.

18. Provide a name for the button (Optional). This name will only be necessary if you wish to identify the button later for additional programming purposes.

19. Click Finish.

CREATING COMMAND BUTTONS TO CARRY OUT RECORD

NAVIGATION/OPERATION

Discussion

The Control Wizards can be used to create command buttons that control record navigation within a form. A command button can thus be set up to move forward or backwards through

Page 86: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 81

records in a form, or to create a new record. This can be useful when creating forms for users who are not familiar with Access.

Form showing command buttons for navigation

Procedure

1. Open the required form in Design view. Although it is possible to carry out this procedure in Layout View, it is easier to position and size the control without the layout feature.

2. Click on the form and press Ctrl A to select all the controls; select the Arrange tab under Form Design Tools and click the Remove Layout command (if active) in the Table group.

NB: If the Remove Layout command is greyed out, it is because the form is not in a layout and you can proceed to the next step.

3. Ensure the Control Wizards button in the Controls group is active.

4. In the Controls group, click the Button command . The mouse pointer changes

to a icon.

5. Click in the form where you want to insert the command button.

6. In the Command Button Wizard, select Record Navigation in the Categories: list box.

7. In the Actions: list, select a relevant navigation command.

8. Click Next.

9. Enter the text for the button or select a picture.

Page 87: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 82

10. Click Next.

11. Provide a name for the button (Optional). This name will only be necessary if you wish to identify the button later for additional programming purposes.

12. Click Finish.

CREATING A COMBO BOX

Discussion

The control wizards can help you create a combo box on a form. A combo box provides you with a list of values from which you can choose. Choosing from a list is much faster and more accurate than remembering a value to be typed. However, you can also type a value directly into a combo box if the appropriate value is not available from the list.

A combo box can be bound to a field, meaning that when you select or enter a value, that value is entered into that field in the corresponding table. A combo box can also be unbound, meaning that when you select or enter a value, it is held in memory to be used in another control or calculation (advanced use only).

Access provides a Combo Box Wizard that guides you through the process of creating a combo box.

Tip If a lookup has been created for a field in a form’s underlying table, it will also appear on the form.

When you use the Combo Box tool, the mouse pointer changes into a copy of the tool with a plus sign (+) above and to the left of it.

Procedure

1. Open the required form in Design view. Although it is possible to carry out this procedure in Layout View, it is easier to position and size the control without the layout feature.

2. Click on the form and press Ctrl A to select all the controls; select the Arrange tab under Form Design Tools and click the Remove Layout command (if active) in the Table group.

NB: If the Remove Layout command is greyed out, it is because the form is not in a layout and you can proceed to the next step.

3. Select the Design tab under Form Design Tools.

4. If necessary, delete the text box and associated label for the control that you want to replace with a Combo Box.

5. In the Controls group, if necessary, activate the Control Wizards

.

6. Click the Combo Box command . The mouse pointer changes to a icon.

7. Click in the Form at the location where you want the combo box to appear.

8. In the Combo Box Wizard, select the option for what you want the combo box to do.

Page 88: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 83

9. The first two options populate the combo box with values that you can then select to edit or add to the field.

10. The third option populates the combo box with values from the form’s underlying table, but also adds a macro to display the record for the selected value.

11. Depending on the option selected above, follow the relevant procedure in the table below.

Option 1

I want the combo box to look up values in a table or

query

Option 2

I will type in the values that I want

Option 3

Find a record on my form based in the value I select

in my combo box

Select the table or query containing the data you want to use for populating the combo box.

Enter the number of columns you want the combo box list to display.

In the Available Fields: list box, select the field(s) that you want to populate the combo box with. Click

after selecting each one.

Click Next. Enter into the table below, the values you want to populate the combo box with.

NB: press [Tab] or [Down/Right Arrow] after each entry NOT [Enter].

Click Next.

In the Available Fields: list box, select the field(s) that you want to populate the

combo box with. Click after selecting each one.

Adjust the column width(s), if necessary.

If you have selected more than one field to populate the combo box with, untick the Hide key

column check box (despite it being recommended!).

NB: If you are setting up the combo box with just one column, this step will not appear.

Adjust the column width(s), if necessary.

Page 89: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 84

Click Next. Click Next. Click Next.

Select a sort order for the combo box list, if required.

If you are using more than one column to populate the combo box with, select which of the columns contains the values that you want to store.

Click Next.

NB: If you are setting up the combo box with just one column, this step will not appear.

Enter a name for the button (Optional). This name will only be necessary if you wish to identify the button later for additional programming purposes.

Click Next. Select the Store that value

in this field: option button. Click Finish.

If you have selected more than one field to populate the combo box with, untick the Hide key column check box (despite it being recommended!).

NB: This option will NOT appear if you are setting up the combo box with just one field.

Adjust the column width(s), if necessary.

Click the drop-down list and choose the field in the form’s underlying table or query where you want the selected item stored.

Click Next. Click Next.

If you have selected more than one field to populate the combo box with, select which of the columns contains the values that you want to store.

Click Next.

NB: If you are setting up the combo box with just one field, this step will not appear.

Enter a name for the button (Optional). This name will only be necessary if you wish to identify the button later for additional programming purposes.

Select the Store that value

in this field: option button. Click Finish.

Click the drop-down list and choose the field in the form’s underlying table or query where you want the selected item stored.

Click Next.

Enter a name for the button

Page 90: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 85

(Optional). This name will only be necessary if you wish to identify the button later for additional programming purposes.

Click Finish.

CREATING A LIST BOX

Discussion

The Control Wizards can help you create a list box on a form. A list box provides you with a list of visible values from which you can choose. If there are too many values to display, a scroll bar appears at the right. You can control how many values the list box displays by adjusting its height.

Choosing from a list is much faster and more accurate than remembering a value to be typed. However, unlike a combo box where, by default, you can enter items NOT in the list, a list box only allows you to choose from the list box; values not present on the list cannot normally be entered into the table.

A list box can be bound to a field, meaning that when you select or enter a value, the value is entered into a field in the corresponding table. A list box can also be unbound, meaning that when you select or enter a value, it is held in memory to be used in another control or calculation (advanced use only).

The List Box Wizard guides you through the process of creating a list box.

Tip You can set the default value for a list box by opening the property sheet (press F4 while in Design View) and typing the desired value in quotation marks in the Default Value property box on the Data page.

Procedure

1. Open the required form in Design View. Although it is possible to carry out this procedure in Layout View, it is easier to position and size the control without the layout feature.

2. Click on the form and press Ctrl A to select all the controls; select the Arrange tab under Form Design Tools and click the Remove Layout command (if active) in the Table group.

NB: If the Remove Layout command is greyed out, it is because the form is not in a layout and you can proceed to the next step.

3. Select the Design tab under Form Design Tools.

4. If necessary, delete the text box and associated label for the control that you want to replace with a List Box.

5. In the Controls group, if necessary, activate the Control Wizards

.

6. Click the List Box command . The mouse pointer changes to a icon.

Page 91: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 86

7. Click the Form at the location where you want the list box to appear.

8. In the List Box Wizard, proceed as described in step 7 for creating a combo box (page 82).

CREATING AN OPTION GROUP

Discussion

An option group on a form provides you with a limited set of values from which you can choose. Choosing from a set of values is often much faster and more accurate than remembering a value to be typed.

With an option group, you can only select one item from the set of alternatives. Option groups, therefore, are best utilised when there a few items only to choose from (ie. 5 or 6). Adding too many options can crowd a form and hinder quick data entry.

An option group has a frame that encloses the set of values. These values appear beside option buttons or check boxes, or on top of toggle buttons.

Example of option (radio) button group

Example of check box group

Example of toggle button group

Page 92: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 87

Although the option group displays its items as text, the item chosen is stored in the underlying table as a numeric field, usually in an ascending order starting with the item at the top of the list as 1.

In the examples above, Customers Types are displayed as text but if a user selects Medium size store, it gets stored in the underlying field as the number 4. To show the textual equivalent for the number (eg. for printing or viewing on screen), a query would have to be created that relates the number to its textual equivalent in another table.

An exception to this rule is if you are using an option group containing two items giving the user a Yes/No choice.

The value given to the options must be 0 for FALSE and -1 for TRUE (see step 9 in the procedure below).

The Option Group Wizard guides you through the process of creating an option group. An option group can be bound to a field in a table or query. However, only the frame is bound to the field.

Procedure

1. Open the form in Design View.

2. Ensure the Control Wizards button is activated.

3. In the Controls group, click the Option Group command . The mouse pointer

changes to a shape.

4. Click in the form where you want the option group to be displayed.

5. In the Option Group Wizard, on each row, type the label names you require.

6. Click Next.

7. Select if you want to make one of the options in the group the default for all new records.

Page 93: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 88

8. Click Next.

9. Accept, or enter, values for each row.

10. In the case of two options giving a yes/no choice, you must enter a 0 value for the No item and a value of -1 for the Yes item.

11. Click Next.

12. Select the Store the value in this field: option. (Save the value for later use. is for advanced purposes only).

13. Select from the drop down list the field to store the selected item.

Page 94: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 89

14. Click Next.

15. Select the type of controls and style required.

16. Click Next.

17. Enter a caption for the option group. This will be used as a label at the top left of the group box.

18. Click Finish.

ADDING A LOGIC CONTROL

Discussion

Some tables contain fields that have a Yes/No field type. These fields can contain a Yes (True) value, a No (False) value, or no value at all and usually display as a check box – ticked for TRUE or unticked for FALSE.

Page 95: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 90

Logic controls like check boxes improve the visual effectiveness of a form and facilitate data entry. With a logic control, the value of a Yes/No field is selected with a single click of the mouse button rather than multiple keystrokes.

You can, however, change the way that a TRUE/FALSE value is entered into a Yes/No field by creating a logic control in the form of an option (radio) button or a toggle button. The way in which these controls indicate a Yes or No value are described in the following table:

Control Appearance

Toggle button Appears “sunken” with a Yes value and “raised” with a No value.

Option (radio) button Contains a dot with a Yes value and appears empty with a No value.

NB: There is no Control Wizard to help you create a logic control so the properties have to be set up manually.

Procedure

1. Open the required form in Design View.

2. In the controls group, click the logic control tool you want to use or or .

3. Click in the form where you want the logic control to be displayed.

4. Select the Design tab under Form Design Tools.

5. In the Tools group, click the Property Sheet command .

6. In the Property Sheet, click the Data tab.

7. In the Control Source box, click the list arrow.

8. Select the field you want bound to the logic control.

9. Close the Property Sheet.

10. Click the label for the logic control.

11. Replace the text with a name for the control.

12. Press the [Enter] key.

Page 96: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 91

Tip You can quickly open or close the Property Sheet by pressing F4.

ACTIVEX CONTROLS

Discussion

Although the controls you see in the Design tab's Controls group will satisfy most of your form needs, you may notice that certain controls commonly seen in Windows dialog boxes are not in there (eg. spin button, scroll bar and date picker).

These and many other controls are, however, available on your system as separate components that either come with the default Windows installation or, are added to the system when you install Microsoft Office (other programs might also add their own controls to the system). There are dozens of these so-called ActiveX controls although only a few are suitable to be used on an Access form and even then, most need additional programming to make them work effectively.

More ActiveX controls are available from Microsoft as well as from non-Microsoft vendors but it is strongly recommended NOT to download or purchase and install them as they could present a security risk to your computer system.

To use ActiveX controls on your forms, ensure that you have responded to the Security Warning at the top of the Access work area and enabled the content. This message will only appear the first time you open the file. Once you have enabled the content, Access makes this a “Trusted Document” and the message will not appear again.

Once an ActiveX control is added, it can be used like any other control. You can move and size it, as necessary, to fit on the form or report. You can also display and change the properties of an ActiveX control.

Procedure

1. Open the required form in Design View.

2. Select the Design tab below Form Design Tools.

3. In the Controls group, click ActiveX Controls command .

4. In the Insert ActiveX Control dialog box select in the list box, Microsoft Date and

Time Picker Control 6.0 (your SP number may vary from that in the screenshot).

Page 97: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 92

5. Click OK. The control is added in the top left corner of the form design view. If the following message appears:

a. click Enable Content in the Security Warning message bar ;

b. re-open the form in design view; and

c. repeat steps 2 to 5 above.

6. Move and size the control as necessary.

7. Add a label next to the control to describe its functionality.

8. Select the control.

9. In the Design tab under Form Design Tools, click the Property Sheet command

in the Tools group.

10. In the Property Sheet, click the Data tab.

11. In the Control Source box, click the list arrow.

12. Select the field you want bound to the control.

13. Close the Property Sheet.

14. View the form and test the control.

Page 98: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 93

15. Save and close the form.

Tip You can quickly open or close the Property Sheet by pressing F4.

Page 99: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 94

EXERCISE

Automated Controls on Forms

1. Open Train9.

2. Open the Payment Form in Design view.

3. Ensure that the Control Wizards are active.

4. Using the Combo Box tool, create a combo box to the replace the Trainer Initials text box and label using the following guidance:

a. Indicate that the combo box should look up values its values in a table.

b. Select Table: Trainer as the table.

c. Include the Initials field in the combo box

d. Accept the default sort order and column width.

e. Store the values entered in the combo box in the Trainer Initials field and label the combo box Trainer Initials.

f. Move/Size the combo box and label to line up and match the other form controls.

5. Using the List Box tool, create a list box to replace the Credit Rating text box and label using the following guidance:

a. Indicate that you want to type in the values for the list box.

b. Use one column and type the values A, B, and C as separate entries.

c. Store the values entered in the list box in the Credit Rating field.

d. Label the list box Credit Rating.

e. Adjust the height of the list box so that it is just able to display all three items.

f. Move/Size the list box and label to line up and match the other form controls.

6. Using the Option Group tool, create an option group to replace the Recorded check box and label using the following guidance:

a. Type Yes and No as the label names.

b. Select Yes as the default choice.

c. Change the default value of the Yes label to -1 and the No label to 0.

d. Store the value entered in the option group in the Recorded field.

e. Use Option (Radio) Buttons as controls and select the Raised style.

f. Enter Recorded? as the label.

g. Move/Size the option group box to line up and match the other form controls.

7. Use the Command Button Wizard to add a command button at the bottom left of the form as follows:

a. The button must run the Payment Information query (Hint: Select the Miscellaneous category in the wizard.)

b. Have the text Payment Info appear on the command button and name the button PaymentInfo.

c. Move/Size the command button on the form, as desired.

8. View the form and click the Payment Info command button to run the query. Close the query and then save and close the Payment Form.

Page 100: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 8 – Special Form Design Techniques

WWP Training Page 95

9. Open Train10.

10. Open the Project Form in Design View.

11. Replace the Start Date text box and label controls with a Microsoft Date and Time

Picker Control (Hint: you will need to open the ActiveX Controls dialog box).

12. Move and size the control as necessary.

13. Add a label next to the control to describe its functionality.

14. Select the ActiveX control and open the Property Sheet.

15. Select the field you want bound to the control in the Control Source box.

16. View the form and navigate through the records. Notice that the calendar changes to reflect the start dates.

17. Repeat steps 10 to 16 above for the End Date control.

18. Close the form and save the changes.

19. Close the database file.

Page 101: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 96

LESSON 9 - SPECIAL REPORT DESIGN TECHNIQUES

In this lesson, you will learn how to:

Add and control report sections

Create a calculated control

Sort data in a report

Group data in a report

Create a summary calculation in a report

Insert a page break in a report

Change the report margins

Create a report from blank

Page 102: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 97

CONTROLLING SECTIONS IN REPORT DESIGN VIEW

Discussion

A report has three basic sections: Detail, Report Header/Footer, and Page Header/Footer.

The Detail section contains the information from the table or query. You add controls in the Detail section that display information. You can display either one record per page or multiple records per page.

The Report Header and Report Footer sections display at the top and bottom of the report in Design view. When you print the report, these sections appear at the beginning and the end of the report only. The header can be used for report titles, while the footer can be used for report totals or other summaries.

The Page Header and Page Footer sections display at the top and bottom of the report in Design view. When the report is printed, these sections appear at the top and bottom of every page. Page headers and footers can contain images, lines, text, or any other controls you want printed on every page.

Report Design View showing all sections

The header sections of a report can be hidden or shown as desired. In most cases, it is preferable to show all headers as they will invariably contain labels or titles to clarify and/or augment the information laid out on the report.

All report sections can be make taller or shorter by clicking and dragging the horizontal line at the bottom of the relevant section.

Resizing the Report Header section

Page 103: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 98

Report Design View also displays gridlines and a horizontal and vertical ruler. These act as aids for accurate positioning and spacing of controls. Like the Header Sections, these can be shown or hidden.

Commands on the Report Design shortcut menu

for displaying headers and footers

Procedure

1. To add Headers and Footers to a report, first open the desired report in Design View.

2. Right click any report section.

3. In the shortcut menu, click the Page Header/Footer command.

4. The report now displays header and footer areas.

NB: If a report already contains a header or footer section and you carry out the actions given in items 3 or 4 above you may be presented with the following message.

CREATING A CALCULATED CONTROL

Discussion

You can add a calculated control to report. A calculated control is not bound to a field, it contains an expression that uses information from fields to calculate a result. The result is not stored in a table, it is calculated and stored temporarily when the report is opened or printed.

You can type the expression that calculates the result directly into the control or open the property sheet and type the expression into the Control Source property box on the Data page. You can also create an expression using the Expression Builder.

A calculated control in a form or report cannot be based on another calculated control in the form or report. However, you can base a calculated control on a calculated field in a query.

Page 104: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 99

Procedure

1. Open the required report in Design View. Although it is possible to carry out this procedure in Layout View, it is easier to position and size the control without the layout feature.

2. Click on the report and press Ctrl A to select all the controls; select the Arrange tab under Report Design Tools and click the Remove Layout command (if active) in the Table group.

NB: If the Remove Layout command is greyed out, it is because the report is not in a layout and you can proceed to the next step.

3. Select the Design tab under Report Design Tools.

4. Click the Text Box command in the Controls group .

5. Click the report where you want the calculated field displayed.

6. If necessary, select the label that was created next to the Text Box and press [Delete] or cut and paste it to a more suitable location.

7. Move/resize the Text Box (it will contain the word “Unbound”) as necessary.

8. Click the Text Box; a cursor will appear at the left of the box.

9. Type = .

Page 105: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 100

10. Enter field names (inside square brackets), mathematical operators and constants as

necessary to create the calculation . Some examples are given in the table at the end of this procedure.

11. Press [Enter] when finished.

12. With the control selected, open the Property Sheet (Design tab).

13. Select Currency in the Format property box.

14. View the report.

15. Save and close the report design.

Example calculation Description =[ItemCost] * 0.2 Returns 20% of the item cost.

=[ItemQuantity] * [ItemPrice] Returns the item quantity field multiplied by the item price field.

=[ItemQuantity] * [ItemPrice] * 0.1 Returns 10% of the item quantity field multiplied by the item price field.

=IIF([Value]>=100,[Value]* 1.1,0) Increases value by 10% but only where the value is greater than or equal to 100, otherwise a 0 is returned.

SORTING A REPORT

Discussion

When initially creating a report, the sort order is determined by either the primary key field or, if the report has been created using the Report Wizard, the order selected in step 3.

You can change the sort order at any time in Report Design View by using the Group, Sort

and Total tool.

Procedure

1. To sort data in a report, first open the report in Design View or Layout View.

2. Select the Design tab under the Report Design (Layout) Tools tab.

Page 106: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 101

3. In the Grouping & Totals group, click the Group & Sort button .

4. In the Group, Sort and Total pane, click the Add a sort button.

5. Select the field you want to sort by.

6. Close the Group, Sort and Total pane.

7. View the report.

8. Save and close the report.

GROUPING DATA IN A REPORT

Discussion

You can group data in reports that have a common field. It is often easier to read a report when data is grouped, since you can more easily find the relevant data.

A grouped report automatically sorts the table by the data in the grouped field. You can nest groups inside one another up to ten levels.

When you group data, you can display a group header and footer that can be used to display information at the top or bottom of each group. For example, you can add a calculated control in a group footer that calculates summary information, such as a total or an average for each group. Additionally, you can control page breaks by specifying how group heading and records should be kept together.

The Group, Sort and Total pane provides all the options you need for your group headers and footers.

Page 107: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 102

Report Design View showing the Group, Sort and Total pane

Example of a report grouped by country

Page 108: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 103

Procedure

1. To group data in a report, first open the report in Design View or Layout View.

2. Select the Design tab under the Report Design (Layout) Tools tab.

3. In the Grouping & Totals group, click the Group & Sort button .

4. In the Group, Sort and Total pane, click the Add a group button.

5. Select the field you want to group by.

6. Move or add the bound control for the field that you have grouped on at the left of the Group Header section that has been created.

NB: This step is not necessary if carrying out this procedure in Layout View.

7. Resize the Group Header section if too tall.

Page 109: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 104

8. If necessary, continue clicking Add a group to create additional sublevels of groupings.

9. When finished, close the Group, Sort and Total pane.

10. View the report.

11. Save and close the report.

CREATING A SUMMARY CALCULATION FOR A GROUP

Discussion

You can create an aggregate function (eg. SUM, AVG, MAX, MIN) for each group that appears in a grouped report. The group footer is usually used to display this information.

Grouped report counting number of customers in each country group

Procedure

1. To create a group summary in a report, first open the report in Design View or Layout View.

2. Follow the procedure in the previous topic and group the report on the field that you want the summary calculation created for. For example, if you want to count the number of customers in each country, you would group on the Country field.

3. In the Group, Sort and Total pane, click the More► button for the group you want a summary for.

4. Click the with no totals drop down arrow.

Page 110: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 105

.

5. Select the field to use in the summary in the Total on drop list. The field you select MUST be visible in the report.

6. Select the aggregate function to use in the Type list.

7. Tick the Show in group footer check box. A group footer section appears in the report design with an unbound control (Text Box) giving the required expression.

8. Move/resize the control as necessary.

9. Add a Label control to the group footer section explaining what the summary total represents (eg. Number of customers or, Total sales for this group).

10. View the report.

11. Save and close the report.

INSERTING A PAGE BREAK

Discussion

When you print a report, Access automatically starts a new page when necessary. You can control the pagination by inserting a manual page break. For example, you could insert a manual page break at the bottom of the Group Footer section to place each group on its own page, or you can insert a page break at the bottom of the Report Header section to create a separate title page for a report.

A more precise method for paginating a report is to add a Force New Page property to the relevant section. This property has three options:

Page 111: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 106

Before Section

After Section

Before & After

The table below gives some examples for using the Force New Page property.

Section Option Description

A group header displaying the year

Before Section The group header is printed at the top of the page, followed by the detail section, group footer, and page footer.

A report detail section After Section The group footer is printed at the top of a new page.

A report header containing the report title and company logo.

After Section The report title and logo are printed on a separate page at the beginning of the report.

Procedure

Manual page break

1. To insert a page break, first open the report in Design View.

2. Select the Design tab under Report Design Tools.

3. In the Controls group, click the Page Break command . The mouse pointer

changes to a shape.

4. Click at the bottom of the section where you want to force a page break. Get as close to the edge of the section as possible without the mouse pointer changing to a no entry

sign .

Adding a manual page break to a group footer section.

Automatic page break (Force New Page property)

1. To insert a page break, first open the report in Design View.

2. Click into the section where you want to force a new page. The section bar will change to black with light grey text.

3. Select the Design tab under Report Design Tools.

4. Click the Property Sheet command in the Tools group .

Page 112: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 107

5. Select the Format tab in the Property Sheet pane.

6. Click in box to the right of Force New Page.

7. Select an option in the drop down list.

8. Close the Property Sheet.

CHANGING THE REPORT MARGINS

Discussion

You can control the margin settings to fit more or less data on a page as necessary. The margins you set for a report are saved and applied each time you print the report.

There are three standard settings for the report margins any one of which can be selected by clicking on the Page Setup tab and then clicking the Margins button.

To control the margins more accurately you can open the Page Set dialog box and enter your own values for the top, bottom, left and right margins.

Page 113: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 108

Procedure

1. To change the report margins, first open the report in either Design or Layout view.

2. Select the Page Setup tab under Report Design (Layout) Tools.

3. Click the Margins command.

4. Select from the list of pre-set margin dimensions.

Alternatively

1. Repeat steps 1 and 2 above.

2. Click the Page Setup command in the Page Layout group.

3. If necessary, select the Print Options tab in the Page Setup dialog box.

4. Set the margin values you require.

5. Click OK.

CREATING A BLANK REPORT

Discussion

You can create a report from scratch in either Layout View or Design View. For example, if a report does not currently exist for a particular table or query, you can create one using the fields in the selected table or query. You can then determine the design of the report by adding fields, control, and options.

By default, a new blank report is opened in Layout View. You can, however, change it to Design View.

Page 114: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 109

Blank report opened in Layout View

Blank report converted to Design View

Procedure

Create a blank report in Layout View

1. To create a blank report, select the Create tab.

2. In the Reports group, click the Blank Report button.

3. A blank report is displayed with the Field List on the right.

4. Click Show all tables.

5. Click the expand button to the left of the required table.

6. Drag the fields you require to appropriate positions on the report.

7. Format the report as required with headers and footers, etc.

8. Click the Save button on the Quick Access Toolbar.

Page 115: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 110

9. Close the report.

Convert a blank report to Design View

1. Proceed as described in steps 1 to 3 above.

2. Select the Design tab under Report Layout Tools.

3. Click the lower half of the View command and select Design View.

4. Resize sections as necessary.

5. Proceed as described in steps 4 to 8 above.

Page 116: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 111

EXERCISE

Using Advanced Report Design

1. Open Train11.

2. Select the Create tab and start a blank report.

3. Change its view to Design View.

4. Drag down the detail area to make a space approx. 10cm (4”) tall.

5. Add the Client ID field approximately 2.5cm (1") horizontally and 1.25cm (1/2”) vertically.

6. Below the Client ID field, add the Course Name, Trainer Initials, and Students fields and approx. 0.5 cm (1/5 “) intervals.

7. Display the report header and footer.

8. Using the toolbox, add a label to the left side of the report header. Enter the text Client Information.

9. Preview the report. Then, close the report and save it as Client Info.

10. Open the Project Information Report in Design view.

11. Add a calculated control (Text Box) below the Trainer Initials text box to calculate the profit margin of each project using the following guidance:

a. The calculation should use the following formula: =[Total Sale]*.08.

b. Format the calculation as currency.

c. Position the calculated control under the Trainer Initials text box.

d. Change the text in the label to Profit Margin.

e. If necessary, resize the label to view all the text, and then, position it under the Trainer Initials label.

12. Preview the report. Notice the profit margin calculation. Then, switch back to Design View.

13. Add a sort for the Trainer Initials field with A on top (Ascending order)

14. Add a second sort for Project ID from smallest to largest.

15. For the Trainer Initials field, add a header and footer section.

16. Ensure the grouping is done “by entire value,” “with no totals” and with a “keep group together on one page” setting.

17. Move both Trainer Initials controls to the Trainer Initials Header section. Move the Profit Margin controls up directly below the Total Sale controls.

18. Create a horizontal line above the Project ID controls from 0cm (0”) to approx. 10cm (4”) on the horizontal ruler.

19. Reduce the height of the Details section by moving the bottom border just under the Profit Margin controls.

20. Preview the report and scroll through the pages. Notice that the trainer initials now appear as a header and the records for each trainer are kept together on a page. Switch back to Design View.

21. Create a new calculated control (Text Box) at the 7.5cm (3”) mark on the horizontal ruler in the Trainer Initials Footer section that sums the profit margin for projects by each trainer using the following guidance:

a. The calculation should use the following formula: =Sum([Total Sale]*.08).

Page 117: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 9 – Special Report Design Techniques

WWP Training Page 112

b. Format the calculated control as currency.

c. Change the text in the label control to Total Profit.

22. Create another horizontal line in the Trainer Initials Footer section, above the Total Profit controls, and from 0cm (0”) to approx. 10cm (4”) on the horizontal ruler.

23. Preview the report.

24. Switch back to Design View.

25. Adjust the top and bottom page margins to Narrow.

26. Preview the report to see the new margins.

27. Close the report and save the changes.

28. Close the database.

Page 118: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 113

LESSON 10 - USING CHARTS

In this lesson, you will learn how to:

Create a chart

Change the chart type

Format chart objects

Page 119: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 10 – Using Charts

WWP Training Page 114

CREATING A CHART

Discussion

Charts and graphs enhance data presented in forms and reports by summarising and illustrating information in a graphical form. Using graphs and charts, users can more easily analyse trends and comparisons. Access itself cannot create charts but it can “borrow” the Microsoft Chart applet (available in all Office applications) and use its Chart Wizard to create the graph for you.

Charts can be either two or three dimensional, depending on the type and amount of data you need to represent. The message a chart conveys should be clear, and you should avoid providing too much information.

The Chart Wizard initially provides 20 chart types for you to choose from. You can later use the Microsoft Chart application to select from a list of 73 standard and 20 custom chart types. The Chart Wizard provides a description of each chart type to assist you in selecting the appropriate type for the data you are using.

Procedure

1. To create a chart only, first create a blank form. If you want to embed the chart in an existing form or report, open the form or report in Design View.

2. Click the Design tab under Form (Report) Design Tools.

3. In the Controls group, click the Chart command .

4. Click and drag the mouse pointer over the form to create a rectangle the size of the intended chart. This can moved and resized later.

5. In the Chart Wizard dialog box, click the table or query you wish to use in the chart.

Page 120: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 10 – Using Charts

WWP Training Page 115

6. Click the Next button.

7. In the Available fields: list, select the field containing the data you want to use and

click the button to transfer it to the Fields for chart: list.

8. Click the Next button.

9. Click the type of chart you want to display.

10. Click the Next button.

11. Click and drag the fields to the where you want them plotted on the chart.

Page 121: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 10 – Using Charts

WWP Training Page 116

12. Click the Next button.

13. Enter a name for the chart and choose whether to display a legend.

14. Click the Finish button.

15. View the form or report in Layout, Form or Report View.

Page 122: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 10 – Using Charts

WWP Training Page 117

CHANGING THE CHART TYPE

Discussion

After creating a chart, you may decide to display the data more effectively with a different chart type. You can change the chart type by activating Microsoft Graph and making the required change in the applet’s window.

Microsoft Chart does not have a Ribbon-based interface and when you first activate it, there is only one toolbar. By clicking and dragging down the small dotted line approximately half

way along the toolbar , you can split it in two and see the full range of buttons more easily.

The mouse pointer changes to a shape when in the correct position.

Splitting the Microsoft Chart application toolbar

Procedure

1. To change a chart type, first open the form/report containing the chart in Design view.

2. Double-click the chart. The chart opens in the Microsoft Chart applet.

3. Click the Chart type button on the toolbar.

4. Select the required chart type button.

Page 123: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 10 – Using Charts

WWP Training Page 118

Or

1. Open the form/report containing the chart in Design view.

2. Double-click the chart. The chart opens in the Microsoft Chart applet.

3. Click the Chart menu and select Chart Type….

4. Select the type of chart you want.

NB: You can also use the Datasheet below the chart to change the values if necessary.

FORMATTING CHART OBJECTS

Discussion

Chart objects are the elements that make up a chart, eg. a data series, a title, a legend, or an axis. When any one of these is selected it can be formatted.

A list of common chart objects is given below:

Chart area

Plot area

Page 124: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 10 – Using Charts

WWP Training Page 119

Series (there may be more than one)

Value axis

Category axis

Legend

Chart title

Axis title(s)

Gridlines

Formatting options vary depending on the object selected, for example, you can change the font of an axis or title but you can’t for a series of the plot background because they don’t contain a font property.

Procedure

1. Open the form/report containing the chart in Design View.

2. Double-click the chart. The chart opens in the Microsoft Chart applet.

3. Click the object that you want to format or, select from the Chart Objects list at the far right of the Standard toolbar.

4. Once the object has been selected, you can:

5. Select a command from the toolbars.

6. Click the Chart menu and select commands.

7. Right click the object and select commands form the shortcut menu.

NB: Commands available will depend on the object selected.

Page 125: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 10 – Using Charts

WWP Training Page 120

EXERCISE

Using Charts

1. Open Train12.

2. Open the Project Information Report in Design view.

3. Extend the Report Header down to approx. 7.5cm (3"). The new chart will be located in this section.

4. Using the Chart Wizard (Hint: click the Chart button in the Control group of the Design tab on the Ribbon), create a graph using the following guidelines:

a. Select the Sales table.

b. Select the Cost field as containing the data for the chart.

c. Select 3-D Pie Chart (bottom row, second from left).

d. Double click the SumofCost box and select None.

e. Choose No Field in the Report fields and Chart fields drop down lists.

f. Accept the default title for the chart and select not to display a legend.

g. Click Finish.

5. View the report in Report View.

6. Return to Design View.

7. Double click the chart to enter Chart Design View.

8. Change the chart type to Column / Clustered Column sub-type, if necessary.

9. Change the chart title to Projects.

10. Apply the Bold Italic style and a 12 point font size to the chart title.

11. Add data labels that show the actual values represented by the chart.

12. Size and position the chart as necessary to view the values.

13. Click back onto the report.

14. View the report in Report View.

15. Close and save the report as Projects Report.

16. Close the database file.

Page 126: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 121

LESSON 11 - USING SUBFORMS/SUBREPORTS

In this lesson, you will learn how to:

Create Main/Sub Form/Report arrangements

Format Main/Sub Form/Report arrangements

Display a subform/report total on the main form/report

Page 127: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 122

CREATING MAINFORM/SUBFORM AND

MAINREPORT/SUBREPORT ARRANGEMENTS

Discussion

You can display a form (or report) within a form (or report). The main form/report includes information from one table and the sub form/report includes information from a second, related table. Main form/report)/sub form/report arrangements are particularly effective at displaying linked data between tables with one-to-many relationships with the main form showing records one at a time from the one side of the relationship and the sub form/report displaying related records from the many side. Sub form/report data can be displayed in either Form view (one record at a time) or Datasheet view (many records displayed at once in a tabular form).

Main form / sub form arrangement (one-to-many relationship)

Main report / sub report arrangement

Individual records from main report (the “One” table)

Navigation buttons for main form

Main form showing individual records from the “one” table

Datasheet sub form showing multiple records from the “many” table

Datasheet sub report showing related multiple records from the “many” table

Datasheet sub report

Page 128: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 123

You can add any number of sub forms/reports to a form/report as well as add a sub form/report within another sub form/report. You should keep in mind, however, that the purpose of a form/report is to make viewing and/or entering data easier. You should avoid cluttering the form/report by positioning the sub form(s)/sub report(s) carefully, assigning a different background colour to each and removing unnecessary items such as navigation buttons and scroll bars. Viewing the properties of the sub form/report is helpful when considering these options.

The SubForm/SubReport Wizard provide the easiest method for creating a sub form or sub report. If you choose not to use the SubForm/SubReport Wizard, you will need to design a sub form/report separately and then insert it into another form or report. You may not want to use the Wizard if you are designing a sub form/report that needs to be different in appearance to the one that the wizard produces.

Subform command on Form Design Tools > Design tab

Subreport command on report Design Tools > Design tab

When you add a subform/subreport to an existing form, it is best to start by creating the main form/report before you create the subform/subreport. The form/report can then be edited so that it contains only the information you need, as well as the desired layout. This form can be added to the design of the main form where it will take on the properties of a subform or subreport.

Page 129: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 124

Procedure (Form)

Using the Wizard to create the sub form

1. Create a form for the table or query that you want to add a sub form to and open it in Design View. If you already have a suitable form for this purpose, open it in Design

View. This will become the Main Form.

2. Create space in the form detail section where you want to add the subform. The spacing can be adjusted more accurately later but initially, ensure there is an area at least 4cm by 4cm.

3. Select the Design tab under Form Design Tools on the Ribbon.

4. Ensure that the Use Control Wizards command is activated .

5. In the Controls group, click the Subform/Subreport button . The mouse pointer

changes to a shape.

6. Click on the main form Detail section where you want to add the sub form. A frame for the subform (you can resize and move it later) and the Subform Wizard appears.

Page 130: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 125

7. Ensure the Use existing Tables and Queries option is selected

8. Click Next.

9. Select the table or query that you want to use for the sub form. This must be a table/query that can be related to the main form table/query via a common field.

10. Select in the list box at the left, the first field from the sub form table/query that you want to display in the sub form.

11. Click the button.

12. Repeat steps 10 & 11 for other fields that you want to display in the sub form.

13. Click Next.

14. Select how to link the sub form table/query to the main form table/query. Access will try to guess and list suggestions in the Choose from a list box. If Access guesses incorrectly or cannot guess at all, you will have to define your own by selecting them in the drop lists.

15. Click Next.

16. Enter the name for the subform.

Page 131: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 126

17. Click Finish.

18. The subform is added in Design View. The subform appears with its controls in a columnar layout, even if the sub form is based on a “many” table. The fields, however, will be tabular when the form is viewed. If the sub form is based on a “one” table, the sub form will also be columnar when viewed.

Page 132: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 127

19. Adjust positioning and sizing of the sub form as necessary.

20. Save all changes, if prompted, and close the form.

Using a previously created sub form

1. Select the table or query that you want to create the sub form from.

2. Select the Create tab.

3. Click More Forms in the Forms group.

4. Click Datasheet.

5. Adjust column widths as necessary.

6. Open the sub form in Design View and make any other required changes (eg. remove fields, alter properties).

7. Save, name and close the sub form.

8. Create a form for the table or query that you want to add a sub form to and open it in Design View. If you already have a suitable form for this purpose, open it in Design View. This will become the Main Form.

9. Create space in the form detail section where you want to add the subform. The spacing can be adjusted more accurately later but initially, ensure there is an area at least 4cm by 4cm.

Page 133: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 128

10. Select the Design tab under Form Design Tools on the Ribbon.

11. Ensure that the Use Control Wizards command is activated .

12. In the Controls group, click the Subform/Subreport button . The mouse pointer

changes to a shape.

13. Click on the main form Detail section where you want to add the sub form. A frame for the subform (you can resize and move it later) and the Subform Wizard appears.

14. Select the Use an existing form option and highlight the required form in the list below.

15. Click Next.

16. Select how to link the sub form table/query to the main form table/query. Access will try to guess and list suggestions in the Choose from a list box. If Access guesses incorrectly or cannot guess at all, you will have to define your own by selecting them in the drop lists.

Page 134: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 129

17. Click Next.

18. Leave the name of the subform as stated.

19. Click Finish.

20. The subform is added in Design View. The subform appears with its controls in a columnar layout, even if the sub form is based on a “many” table. The fields, however, will be tabular when the form is viewed. If the sub form is based on a “one” table, the sub form will also be columnar when viewed.

Page 135: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 130

21. Adjust positioning and sizing of the sub form as necessary.

22. Save all changes, if prompted, and close the form.

Procedure (Report)

Using the Wizard to create the sub report

1. Create a basic report for the table or query that you want to add a sub report to and open it in Design View. If you already have a suitable report for this purpose, open it in Design View. This will become the Main Report.

2. Create space in the report Detail section where you want to add the sub report. The spacing can be adjusted later but initially, ensure there is an area at least 4cm by 4cm.

3. Select the Design tab under Report Design Tools on the Ribbon.

4. Ensure that the Use Control Wizards command is activated .

5. In the Controls group, click the Subform/Subreport button . The mouse pointer

changes to a shape.

6. Click in the Detail section of the main report where you want to add the sub report. A frame for the sub report (you can resize and move it later) and the SubReport Wizard appears.

Page 136: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 131

7. Ensure the Use existing Tables and Queries option is selected

8. Click Next.

9. Select the table or query that you want to use for the sub report. This must be a table/query that can be related to the main report table/query via a common field.

10. Select in the list box at the left, the first field from the sub report table/query that you want to display in the sub report.

11. Click the button.

12. Repeat steps 10 & 11 for other fields that you want to display in the sub report.

13. Click Next.

14. Select how to link the sub report table/query to the main report table/query. Access will try to guess and list suggestions in the Choose from a list box. If Access guesses incorrectly or cannot guess at all, you will have to define your own by selecting them in the drop lists.

Page 137: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 132

15. Click Next.

16. Enter the name for the sub report.

17. Click Finish.

18. The sub report is added in Design View.

Page 138: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 133

19. Save all changes, if prompted, and close the report.

Using a previously created sub report

1. Select the table or query that you want to create the sub report from.

2. Select the Create tab.

3. Click Report in the Reports group.

4. Open the sub report in Design View and make any other required changes (eg. remove fields, alter properties).

5. Save, name and close the sub report.

6. Create a report for the table or query that you want to add the sub report to and open it in Design View. If you already have a suitable report for this purpose, open it in Design View. This will become the Main Report.

7. Create space in the report Detail section where you want to add the sub report. The spacing can be adjusted later but initially, ensure there is an area at least 4cm by 4cm.

8. Select the Design tab under Report Design Tools on the Ribbon.

Page 139: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 134

9. Ensure that the Use Control Wizards command is activated .

10. In the Controls group, click the Subform/Subreport button . The mouse pointer

changes to a shape.

11. Click in the Detail section of the main report where you want to add the sub report. A frame for the sub report (you can resize and move it later) and the SubReport Wizard appears.

12. Select the Use an existing report or form option.

13. Select the required report in the list box below.

14. Click Next.

15. Select how to link the sub report table/query to the main report table/query. Access will try to guess and list suggestions in the Choose from a list box. If Access guesses incorrectly or cannot guess at all, you will have to define your own by selecting them in the drop lists.

Page 140: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 135

16. Click Next.

17. Enter the name for the sub report.

18. Click Finish.

19. The sub report is added in Design View.

Page 141: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 136

20. Save all changes, if prompted, and close the report.

FORMATTING MAIN/SUB FORM/REPORT ARRANGEMENTS

Discussion

In order to improve the effectiveness or appearance of a main/sub form/sub report, you can change its structure and formatting in the same way as you would any other form or report.

Many changes to the positioning and formatting of controls can be done in Layout View. Simply select the various sections or controls on the forms and use commands on the Ribbon or open the Properties Pane and change settings there.

Certain changes, however, can only be effected in Design View. One such command is controlling how the subform/subreport displays its information.

As explained in the previous topic, when creating a main/sub arrangement using the Wizard, a datasheet (tabular) form is created if the underlying table for the subform/subreport is a “many” table, and a single form is created if the underlying table for the subform/report is a “one” table.

NB: this can be very confusing because in Design View, the subform/subreport always looks the same!

This can be changed by opening the subform/subreport in Design View and changing its Default View property.

Page 142: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 137

The pictures below describe options available for this setting.

Main/subform arrangement (one-to-many relationship) with the subform in Datasheet view - multiple records shown.

Main/subform arrangement (one-to-many relationship) with the subform in Single Form view – subform needs to be navigated to view records.

Main/subform arrangement (one-to-many relationship) with the subform in Continuous Form view – subform can be scrolled OR navigated to view all records.

Page 143: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 138

Tip

A simple but effective way of improving the appearance of a single or continuous form (whether main form/report or subform/report is to open the form or report in Layout View, select the Format tab under Form (or Report) Layout Tools and click a style in the AutoFormat gallery.

You can open a subform into a separate Design window by right-clicking a control (eg. text box or label) on the desired subform and then selecting the Subform in New Window command from the shortcut menu or, by right clicking it in the Navigation Pane and selecting Design View.

If using the datasheet of continuous forms default view, it can be useful to hide the navigation buttons because they are not especially useful and serve only to clutter the form and cause some confusion. This is achieved by opening the Property Sheet and changing the form’s Navigation Buttons property to No.

Page 144: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 139

Main/subform arrangement with subform’s Navigation Buttons removed

Procedure

To change the way the form is displayed

1. Open the subform in Design View.

2. Select the Design tab under Form Design Tools.

3. Click Property Sheet in the Tools group .

4. Click the Selection type: drop down list.

5. Select Form.

.

6. Ensure the Format tab is selected.

7. Click in the box to the right of Default View.

8. Select your preference from the drop down list.

9. Press [Enter].

To remove the navigation buttons

1. Proceed as in steps 1 to 6 above.

2. Click in the box to the right of the Navigation Buttons.

3. Select No from the drop down list.

4. Press [Enter].

5. Save the form and close Design View.

6. Make the necessary changes.

7. Save and close the form.

Page 145: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 140

DISPLAYING A SUBFORM/SUBREPORT TOTAL

Discussion

Forms and reports often include totals of the information they contain. These totals are easily created by adding a calculated control to the form or report that contains an expression to find the desired total.

Expressions are used to obtain information you cannot obtain directly from the tables in your database. For example, if you have a table that contains the quantity and cost of various items, you could use an expression to multiply the quantity and the cost to obtain the current inventory value.

Every time you use a form/report, Access calculates any expressions contained in the form/report, helping you keep your information as accurate as possible.

Some examples of expressions are listed in the following table:

Expression Result

=[Cost]+[Shipping]+[Markup] Adds the value of the Cost field, the value of the Shipping field, and the value of the Markup field of an item to produce the Total field

=[Price]*0.15 Multiplies the Price field of an item by a constant discount of 15%

=Date() Provides the current date in your computer system

You may want to include a total of information, contained in a subform/subreport, in the main form/report total. For example, an Orders form may contain a control for shipping

charges. The information in the Product subform may include a total, such as the total cost of all the products ordered.

You can display this subform total on the main form so that you can add the shipping charges to this total to create a grand total. This option is performed by adding a control to the main form/report, which refers to the desired subform/subreport total control, to display the information.

Main form / sub form showing a total for items in the subform

Page 146: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 141

Main report / sub report showing a total for items in the sub report

The expression in the main form/report control that refers to the subform/subreport control defines the name of the subform/subreport and the name of the subform/subreport control being used in the following format:

= [Name of the Subform/Subreport]![Name of the Subform/Subreport Control]

Procedure

Step 1 – create a calculation in the subform

1. Open the subform/subreport in Design View.

2. Press [Ctrl] + A to select all controls on the form.

3. Select the Arrange tab under Form (or Report) Design Tools.

4. Click Remove in the in the Control Layout group.

5. Select the Design tab under Form (or Report) Design Tools.

6. Click the Text Box command .

7. Click on the Form or Report detail area.

8. Click the Label for the text box control.

9. Press [Del].

10. Click in the Text Box.

11. Enter the required expression (formula).

Page 147: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 142

12. Press [Enter].

13. Select the Design tab under Form (or Report) Design Tools.

14. Click Property Sheet in the Tools group .

15. Select the Other tab in the Property Sheet pane.

16. Click the box to the right of the Name property.

17. Type a short but descriptive name for the Text Box control, eg. CountofProducts or TotalOfOrders. It is good practice to avoid using spaces in the name.

18. Press [Enter].

19. Select the Format tab in the Property Sheet pane.

20. Click in the box to the right of the Visible property.

21. Select No from the drop down list.

APPLIES TO FORMS ONLY - If the subform has its Default View property set to Datasheet, setting the Visible property to No will still display the field. Carry out the following:

a. View the form in Datasheet view.

b. Right-click the column that displays the Text Box data.

c. Select Hide Fields.

22. In ALL cases, save and close the form.

Step 2 - refer to the text box value on the Main Form/Report

1. Open the main form in Design View.

2. Press [Ctrl] + A to select all controls on the form.

3. Select the Arrange tab under Form (or Report) Design Tools.

4. Click Remove in the in the Control Layout group.

5. Select the Design tab under Form (or Report) Design Tools.

6. Click the Text Box command .

7. Click on the Form or Report detail area where you want to display the control.

8. Move and/or resize the Text Box and associated Label as necessary.

Page 148: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 143

9. Click on the Label.

10. Type a descriptive name for the contents of the Text Box.

11. Click in the Text Box.

12. Type a reference to the control on the subform, the syntax is: = [name of form]![name of control].

13. Press [Enter].

14. Save and close the form.

Page 149: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 11 – Using Subforms and Subreports

WWP Training Page 144

EXERCISE

Using Subforms/Subreports

1. Open Train13.

2. Open the Invoice Form in Design view.

3. Use the SubForm Wizard to create a subform at the bottom centre of the form.

4. Insert the existing Project Form as a subform.

5. Select the appropriate option from the list box to link the main form and subform by the Project ID field. Name the subform Project Info.

6. Delete the subform’s label box.

7. Size and position the subform control so that all the fields appear, if necessary.

8. Switch to Form view to see the subform.

9. Close the database file.

Page 150: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 145

LESSON 12 - WORKING WITH INDEXES

In this lesson, you will learn how to:

View indexes

Create a single field index

Create a multiple field index

Delete an index

Create a multiple field primary key

Page 151: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 12 – Working with Indexes

WWP Training Page 146

INTRODUCTION

Discussion

You can use indexes to help Access perform quicker sorts and searches. An index in Access is a data structure which stores the sort order of a table based on the indexed field(s).

When a table is sorted by an indexed field, Access uses the index to sort the table very quickly. It is helpful to index fields that are often used to search or sort the table data. Where a field contains many different values indexing can significantly speed up queries.

You should index the fields you use regularly to sort or search for data.

You cannot create an index for Memo, OLE, or Hyperlink fields.

Indexes have important properties that are listed in the following table:

Property Description

Primary

Designates whether or not the index is the primary key for the table. In other words, this property designates whether or not the data in the indexed field will be used to uniquely identify each record. If this property is set to Yes, the Unique property must be set to Yes.

Unique Designates whether or not the values in the indexed field must be unique for each record. You can set this property to Yes without setting the Primary property to Yes.

Ignore Nulls Determines whether or not records with null values in the indexed field are included in the index. The default setting is No, which means that null values are included.

Procedure

1. Open in Design view, the table whose indexes you wish to view.

2. Select the Design tab under Table Tools.

3. In the Show/Hide group, click the Indexes button.

4. The Indexes box is displayed.

Page 152: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 12 – Working with Indexes

WWP Training Page 147

CREATING A SINGLE FIELD INDEX

Discussion

You should index at least one field for each table to maximize performance. You should select a field you are likely to use in searches and sorts.

When you change the Indexed property of a field to Yes, you can choose whether or not to allow duplicates. If you choose the No Duplicates option, Access will not allow duplicate values to be entered into the field.

Procedure

1. Open the table in Design view.

2. Click the field you require to be an index.

3. In the Field Properties pane, click the list arrow of the Indexed box.

4. Select the option you require.

Page 153: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 12 – Working with Indexes

WWP Training Page 148

CREATING A MULTIPLE FIELD INDEX

Discussion

If you often search on a combination of fields, you can create an index on multiple fields to speed up the searches and sorts. For example, if you want to sort customers in order by region and alphabetically within each region, you can create an index on the Region and Customer fields.

You must create a multiple field index in the Indexes window. All the fields you want to include in the index should be listed under the same index name. You can include up to ten fields in an index.

Procedure

1. Open, in Design view, the table you wish to add multiple indexes to.

2. Select the Design tab under Table Tools.

3. In the Show/Hide group, click the Indexes button .

4. Click in the first blank field in the Index Name column.

5. Type a name for the index.

6. In the Field Name column, click the drop down arrow.

7. Select the field you want to include in the multiple index.

8. In the Sort Order column, click the list arrow and choose the required sort order.

9. Select the next blank box in the Field Name column.

10. Select the second field you want to include in the multiple index.

11. In the Sort Order column, click the list arrow to choose the sort you require.

12. Repeat adding more fields as required to the multiple index.

13. Close the Indexes box.

Multiple index name Location used for faster finding and filtering of data by

Country, State/Province and City fields.

Page 154: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 12 – Working with Indexes

WWP Training Page 149

DELETING AN INDEX

Discussion

Indexes take up disk space and can slow down the process of adding, editing, and deleting records. In fact, if there are a limited number of different values in a field, the sort or search speed is not significantly increased by indexing the field. Therefore, you can delete any unwanted indexes to increase efficiency.

Procedure

1. Open in Design view, the table you wish to delete an index from.

2. Select the Design tab under Table Tools.

3. In the Show/Hide group, click the Indexes button.

4. Click the row selector to the left of the row containing the index you intend to delete.

5. Press the [Delete] key.

6. Close the Indexes box.

CREATING A MULTIPLE FIELD PRIMARY KEY

Discussion

There are times when it is not possible to uniquely identify fields with the values in a single field. Therefore, Access allows you to create a primary key using multiple fields. When you set a primary key using multiple fields, the combination of the information in the fields must be unique.

For example, you have a table that contains line items for customer orders. The order number is entered for each customer. Because you will most likely have multiple customers with multiple orders, the order number associated with each customer may not be unique. Also, a particular item number may appear in multiple orders.

The item numbers, therefore, may not be unique, hence, you cannot create a primary index on either of these fields by themselves. The solution is to create a primary key index on both fields thus allowing each item to appear only once on each order.

Procedure

1. Open the required table in Design view.

2. Select the Design tab under the Table Tools.

3. Click the row selector to the left of the row containing the first field for the primary key.

4. Hold down the [Ctrl] key and click the row selector for the second primary key field.

Page 155: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 12 – Working with Indexes

WWP Training Page 150

5. In the Tools group, click the Primary Key command .

6. Click the Indexes button to see the multiple primary key.

Page 156: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 12 – Working with Indexes

WWP Training Page 151

EXERCISE

Working with Indexes

1. Open Train14.

2. Open the Invoice table in Design view.

3. Open the Indexes window.

4. Index the Client ID field, allowing duplicates.

5. Create a multiple field index called Client/Project. The first field in the index should be Client ID and the second field should be Project ID. Use the Ascending sort order for both.

6. Close the Indexes window. Then, close the Invoice table without saving the changes.

7. Open the Project table in Design view.

8. Open the Indexes window and delete the existing indexes. Close the Indexes window.

9. Create a multiple field primary key that includes the Project ID and Client ID fields.

10. Open the Indexes window to view the primary key fields. Then, close the Indexes window.

11. Close the Project table without saving the changes.

12. Close the database file.

Page 157: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 152

LESSON 13 - WORKING WITH MACROS

In this lesson, you will learn how to:

Introduction to the Macro Designer

Create a macro

Save a macro

Run a macro

Use single step mode for testing

Edit an existing macro

Manage message box text in macros

Page 158: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 153

INTRODUCTION TO THE MACRO DESIGNER

Discussion

A macro performs a set of commands in sequence. While macros in word processors and spreadsheets are used mainly to duplicate keystrokes or mouse movements, macros in Access often automate an action or a series of actions. Such actions include opening tables, printing forms, finding records, or applying filters. Macros can even be used to add command buttons, and build complete applications.

In Access 2010, there are several new features in macro design and use that will appeal to the developer and basic user alike. These include an improved Macro Designer (formerly called the Macro Builder), table-based data macros, and changes to how you create expressions. The improved Macro Designer helps you create macros that are more flexible and easier to read and more in line with how the code would be written in VBA. Macros can now also be attached to tables so that any object that is created based on that table inherits the macro (see Appendix C on page 234). If using the Expression Builder to enter action arguments, Access uses “IntelliSense” to enable easier reference to database objects, fields and functions.

The Macro Designer window

The Expression Builder using “Intellisense” to display a list of table fields

The Macro Designer has two panes; the Code Sheet and the Action Catalog.

Page 159: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 154

The Code Sheet is where you create the “instructions” for the macro to execute, and the Actions Pane is where you can select items for the macro instructions. At the simplest level, a macro is made up of two items.

An action (or actions) for the macro to perform.

Arguments that elaborate how to perform the action(s). These are not always necessary.

Furthermore, macros may contain:

conditions for performing actions and associated arguments; and

comments to describe or explain something about the macro.

At a more advanced level, macros may also be composed from:

Groups - used for organising and structuring macro instructions; and

Submacros - used to organise frequently used, re-useable “snippets” of instructions that can be “called” by various methods.

NB: Users who are familiar with Group Macros in earlier versions of Access should note that Groups in Access 2010 are not the same thing. The equivalent to Group Macros in Access 2010 is Submacros (see page 186).

Procedure

1. Select the Create tab on the Ribbon.

2. Click Macro in the Macros & Code group.

3. The Macro Designer window is displayed.

CREATING A MACRO

Discussion

A macro carries out actions. You place each action in the Code Sheet arranged from top to bottom in the order that they are to be performed. For example, a Maximize action maximizes the window opened in the step immediately preceding it.

Page 160: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 155

You can add comments to the macro in order to explain and clarify actions and arguments. Comments are useful not only for yourself to remember why and how a particular action has been set up, but also to help users who may later have to work with your database.

The first step in creating a simple macro is selecting the first action for the macro to perform. This can be done from either the Add New Action drop down list in the Code Sheet or from the Action Catalog pane. If you select an action in the Actions Catalog pane, Access displays a helpful message describing the selected action at the bottom of the pane.

Once selected, the action is displayed in a “code block” in the Code Sheet with any associated arguments listed below. Depending on the action selected some arguments may require user input, some may have a default value set, some may be left blank and with some actions, no arguments are required at all. If a required argument is missing, the macro stops when the action containing the missing argument is encountered.

In the screenshot below, an OpenTable action has been selected. Arguments for the action are shown below, viz. Table Name; View; Data Mode. Table Name requires user input; View and Data Mode have changeable, default values set.

The screenshot below shows an ApplyFilter action. This action is applied to the currently active object and extracts just those records where the CreditLimit field has a value greater than 5000.

In the example below, the actions above have been combined so that the macro opens the Customer Financial table and then filters it to display only the record where the credit limit is over 5000. It also includes a comment at the top (in green font colour) explaining its use.

Page 161: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 156

Tip Program flow items can also be selected from the Add New Action drop down list in the Code Sheet.

Tip

Expand and collapse code blocks with the Left and Right arrow keys.

The CTRL + Up and CTRL + Down keystrokes moves the selected action up and down.

CTRL + drag copies the selected actions when you need to quickly duplicate instructions.

Tip To add a comment quickly, click in the Add New Action box and type an apostrophe ( ‘ ) followed by the comment text. Press [Enter].

Tip Hold the mouse pointer over an action or argument to see a Help Tip. Click onto an action block or argument box and press F1 to display a context sensitive Help page.

Tip When entering argument text, press SHIFT F2 to open the Zoom window and see the text more clearly.

Tip

You can carry out an “instant search” for an action in the Actions Catalog by typing the first few characters in the Search box.

Remove the search filter when finished by clicking the button.

Page 162: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 157

Tip

If the Action Catalog pane is not displayed, click the Action Catalog

command in the Show/Hide group under Macro Design Tools.

Tip

Each code block has a collapse/expand button at the top left corner. This can be used for hiding/showing the detail inside a block thus making the overall macro clearer and easier to view and understand.

Collapse button Expand button

Procedure

1. Select the Create tab on the Ribbon.

2. Click Macro in the Macros & Code group .

3. Click the Add New Action drop down list arrow or navigate to an action under Actions in the Actions Catalog.

4. Select the action you want to use.

5. In the action code block, enter arguments as required. There is a limit of 255 characters for argument text.

6. In the Actions Catalog pane double-click Comment, if required, enter explanatory text for the macro of the action.

7. Enter further actions and comments as required.

8. When you close the Macro Designer, you will be prompted to save the macro.

Tip

Access 2010 does not initially display all macro actions. To see a full list when you click the Add New Action drop down list, click the Show All Actions command in the Show/Hide group of the Macro Tools >

Design tab .

Page 163: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 158

There are dozens of actions that Access macros can perform and many ways of using them and setting up their arguments. This booklet can only give a guide to the tools and techniques available. Users will need to carry out further reading of Help pages as well as experimentation, practice and trial and error to achieve their required results. Excellent, detailed descriptions of all Access 2010 macro actions can be found by following the link given below to the Microsoft Developer Network (MSDN) pages:

http://msdn.microsoft.com/en-us/library/office/ff841324

SAVING A MACRO

Discussion

After creating a macro, you must save it before you can test or run it. When you attempt to save a macro or close the Macro window without saving, a Save As dialog box opens with the default name of Macro# (numbered consecutively). The name that you give the macro appears in the Macros section of the Navigation Pane.

You can rename a macro. However, if you rename a macro, it may no longer run, depending on how you initiate the macro. Instead, it is a good idea to copy a macro, rename it, and then edit it in order to create macros that perform similar tasks.

Procedure

1. To save a macro, first create the required macro.

2. Click the Save button on the Quick Access Toolbar.

3. In the Save As dialog box, enter a name for the macro.

4. Click OK.

USING SINGLE STEP MODE FOR TESTING A MACRO

Discussion

Access runs macros so quickly that you may not be able to see each action as it is performed. If you wish to confirm that the actions are being performed correctly, you can step through the macro. Single step mode is particularly useful when a macro contains numerous actions or arguments, or when a macro does not seem to perform as planned.

When you step through a macro, Access pauses before each action, allowing you to view each step. The Macro Single Step dialog box opens, displaying the macro name, condition (if applicable), action name, and selected arguments.

Page 164: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 159

The Macro Single Step dialog box has three buttons: Step, Stop All Macros, and Continue. You select the Step button to perform the action in the dialog box. If there are no errors, the next action appears in the dialog box. If you want to stop running the macro in this mode, you select the Stop All Macros button. The macro stops running and the dialog box closes. When you want to stop stepping through the macro and run the remaining steps, you select the Continue button. The remaining macro actions are then completed.

You should only use single step mode when working in the Macro Designer window. When you enable single step mode, it remains activated throughout the current Access session. All macros will run in single step mode until the mode is disabled.

If an error does occur, you can make the changes in the Macro Designer window. After you make the changes to a macro, you should retest it.

Procedure

1. Open the macro you want to “step” in Design view.

2. Select the Design tab under Macro Tools.

3. Click the Single Step command in the Tools group .

4. Click the Run command.

5. Click the Step button to perform the first action in the macro.

6. Repeat as necessary until the macro finishes.

7. If the macro encounters an action it cannot perform, a message box is displayed stating the action could not be carried out.

8. Click the Stop All Macros button to stop the macro.

9. When you have finished testing and correcting the macro, click the Single Step command again to de-activate step mode and allow the macro to run normally.

The Macro Single Step window

Error message if action cannot be performed

Page 165: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 160

The Macro Single Step window showing an error number

RUNNING A MACRO

Discussion

You can run a macro from the Navigation Pane by double-clicking the macro name or right-clicking it and selecting Run from the shortcut menu.

You can also run the macro when the macro is in Design View by clicking the Run command on the Macro Tool > Design tab . A warning box opens if required arguments are missing, incorrectly entered or if the macro cannot run for any reason.

Procedure

1. To run a macro from Design view, click the Run button in the Tools group of the Design tab on the Ribbon.

2. To run a macro from the Navigation Pane, double-click the macro name or, right-click the macro name and select Run from the shortcut menu.

Page 166: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 161

EDITING AN EXISTING MACRO

Discussion

After you have created a macro, in the Macro Designer window you can use various methods to add or delete existing actions, move them into a different order or modify their arguments.

After you make the desired changes, you must save the macro to retain the changes. It is a good idea to test the edited macro using single step mode (see previous topic). You must remember to disable single step mode after testing a macro.

Procedure

Adding an additional action or comment

1. In the Navigation Pane, right click the macro you want to edit.

2. Select Design View in the shortcut menu.

3. In the Code Sheet, select the code block where you want to add a new action or comment beneath.

4. If adding a comment, double click Comment under Program Flow in the Action

Catalog pane.

.

5. If adding a new action, in the Actions Catalog, expand the folder containing the action you want to add.

6. Double click the required action.

7. Complete arguments as necessary.

8. Save and close macro Design View.

Alternatively

1. Click the Add New Action drop down list at the bottom of the Code Sheet.

2. Select the required action or, select Comment at the top of the list.

3. Enter any required arguments or, in the case of a comment, the required text.

4. Click the Move up button at the top right of the code block until the action or comment is in the required position.

Page 167: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 162

5. Save and close macro Design View.

Modifying arguments for an action

1. In the Navigation Pane, right click the macro you want to edit.

2. Select Design View in the shortcut menu.

3. In the Code Sheet, select the action code block that you want to modify the arguments for.

4. Make changes as required.

5. Save and close macro Design View.

Deleting an action or comment

1. In the Navigation Pane, right click the macro you want to edit.

2. Select Design View in the shortcut menu.

3. In the Code Sheet, select the code block that you want to delete.

4. Click the Delete button in the top right corner of the block.

5. Save and close macro Design View.

Moving an action or comment

1. In the Navigation Pane, right click the macro you want to edit.

2. Select Design View in the shortcut menu.

3. In the Code Sheet, select the code block that you want to move.

4. Click the Move up button or Move down button in the top right corner of the block as often as necessary until the block has been moved to the required position.

5. Save and close macro Design View.

MANAGING LONG TEXT IN MESSAGE BOXES

Discussion

Access word wraps message box text at 162 characters. This means that if your message many characters (the limit is 255), the box can become quite wide before the line is automatically broken.

You may, therefore, wish to create your own line and/or paragraph breaks. This can be achieved by starting the message with an equal symbol ( = ), placing inside quote marks ( " ) any static text required and joining this with an ampersand ( & ) to the special functions Chr(10) (line feed) or Chr(13) (carriage return) where you want to create the line break. For practical purposes, either Chr(10) or Chr(13) can be used.

The sample below shows a long message with no line or paragraph breaks:

Page 168: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 163

The following message argument…

="Credit limit over £5000 is not permitted." & Chr(10) & "Click OK to this message and refer to the following window for approval procedures."

... will break the text split across two lines as shown below:

To create a blank line between paragraphs use two Chr(13) functions separated by an ampersand, eg:

= "Static text A" & Chr(13) & Chr(13) & "Static text B"

Other Chr functions that can be used in a similar way are Chr(9) - Tab character and Chr(149) bullet. Eg.

= "Contact points for credit limit authority are:" & Chr(13) & Chr(13) & Chr(149) & Chr(9) & "Bob Fowler - North and West regions" & Chr(13) & Chr(149) & Chr(9) & "Alison Crosby - East, South and Central regions"

…will produce the following message:

Procedure

1. Open the macro in Design View.

2. Add a new or select an existing Message Box action.

3. Click in the Message argument.

4. Type an equal symbol ( = ).

5. Type a quote mark ( " ) .

6. Start typing the text for your message.

7. At the point at which you want to break the line, type a quote mark ( " ).

8. Type and ampersand ( & ).

9. Type Chr(10) or Chr(13).

Static text inside quote marks Static text inside quote marks Line feed inside

ampersands

Page 169: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 164

10. Type an ampersand ( & ).

11. Type a quote mark ( " ).

12. Continue typing the message text.

13. At the end of the text, type a quote mark ( " ).

14. Save, close and test the macro.

RUNNING A MACRO FROM THE DATABASE TOOLS TAB

Discussion

You can run a macro using the Database Tools tab on the Ribbon. This option allows you to execute a macro from almost anywhere.

When the Run Macro dialog box opens, you can either type the name of the macro in the text box or select the macro name from a list.

Procedure

1. Select the Database Tools tab.

2. In the Macro group, click the Run Macro command.

3. In the Run Macro dialog box, type or select the macro you want to run.

RUNNING A MACRO FROM THE QUICK ACCESS TOOLBAR

Discussion

You can run a macro using the Quick Access Toolbar. Since the Quick Access Toolbar is always visible, this option allows you to run a macro at any time and with any Access object in any view.

The default Quick Access Toolbar

After creating a macro, you can add the macro to the Quick Access Toolbar, simplifying access to that macro. After creating a macro, the macro name is displayed in the list of available commands when the Quick Access Toolbar is customised.

A macro button on the Quick Access Toolbar will display the name of the macro when the mouse button is held over the button.

For further information on customising the Quick Access Toolbar, see Appendix A on page 212)

Page 170: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 165

Procedure

1. Click the Customize Quick Access Toolbar drop down arrow to the right of the

Quick Access Toolbar .

2. Click More Commands… in the menu.

3. Click the Choose commands from: list arrow.

4. In the list, click Macros.

5. Click the macro you wish to add from the left column.

6. Click the Add button .

7. Click the Modify… button .

8. In the Modify Button dialog box, type a name in the Display name: box.

9. Click the icon you want to use for the button.

10. Click the OK button.

11. Repeat steps 5 to 10 for any more macros that you want to add to the Quick Access

Toolbar.

Page 171: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 166

12. When finished, click the OK button to close the Access Options. The button is displayed on the Quick Access Toolbar.

Quick Access Toolbar with buttons to run macros added

Tip

Buttons added to the Quick Access Toolbar remain visible irrespective of which database is open. If, therefore, the database containing the macros is not open, clicking a button will have no effect.

Page 172: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 167

EXERCISE

Creating Macros

1. Open Train15 - this database uses overlapping windows instead of tabbed documents.

2. Create a new macro. Enter the following actions and arguments:

Action Arguments

OpenForm Form Name: Invoice Form Data Mode: Read Only

MoveAndSizeWindow Right:0 Down: 0 Width: 10000 Height: 5000

OpenForm Form Name: Payment Form Data Mode: Read Only

MoveAndSizeWindow Right: 0 Down: 7000 Width: 10000 Height: 2000

3. Add a Comment block at top of the code sheet containing the text: This macro opens and tiles the Invoice and Payment forms.

4. Save the macro as Open Invoice/Payment Forms.

5. Run the macro from the Macro Designer window.

6. Close the open forms.

7. In the Macro Designer, enable single step mode.

8. Run through the macro step-by-step to identify any errors.

9. Close the open forms and return to the Macro Designer.

10. In the second MoveAndSizeWindow action, edit the Down argument to 5000 and the Height argument to 5000.

11. Disable single step mode.

12. Save the macro and close the Macro Designer.

13. Run the Open Invoice/Payment Forms macro using the Run Macro command on the Database Tools tab of the Ribbon.

14. Close the forms.

15. Create a new macro.

16. Add actions and arguments to close the Invoice Form and the Payment Form (Hint: you will need two separate CloseWindow actions for this).

17. Save the macro as CloseForms and close the Macro Designer.

18. Open the Invoice Form in Design View.

Page 173: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 13 – Working with Macros

WWP Training Page 168

19. Use the Command Button Wizard to create a command button to run the CloseForms macro.

20. Move/Size the button at the bottom of the form; use the screen shot below as a guide.

21. Save the form.

22. Add a button to the Quick Access Toolbar to run the Open Invoice/Payment Forms.

23. Run the Open Invoice/Payment Forms using the button created in step 22 above.

24. Use the command button on the Invoice Forms to close the forms.

25. Close all open forms.

26. Remove the macro button from the Quick Access Toolbar.

27. Close the database.

Page 174: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 169

LESSON 14 - FURTHER MACROS

In this lesson, you will learn how to:

Assign a macro to a form or report control

Assign a macro a form command button

Create and assign a macro directly from a form or report control

Add a simple IF condition to a macro

Use the Expression Builder to create conditions

Use advanced IF conditions using ELSE and ELSEIF

Create submacros

Handle error in a macro

Use groups in macro code

Create an Autoexec macro

Page 175: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 170

INTRODUCTION

Discussion

Properties allow you to specify the appearance and behaviour of objects in a database. Objects include tables, queries, forms, and reports, as well as controls within reports or forms.

The Property Sheet displays the properties of a selected object. One of the tabs on the Property Sheet is Events. An event occurs when an action is performed on an object, eg. it is clicked with the mouse pointer, data is changed, a forms opens or closes and many others. Events usually occur as the result of user action.

By making use of events, you can automatically get a macro to run when a user performs certain actions in the database. Access 2010 introduces events on tables so that you can run macros to perform actions when records are added, deleted or updated. See Appendix C on page 234 for assigning macros to table events.

The events available vary considerably depending on the object in question. The table below shows events associated with a form text box. Other form objects have similar events while others have very different ones. .

Event Property Action is initiated

On Click by clicking and releasing the primary mouse button on the control

Before Update before the data in a control is updated

After Update after the data in a control is updated

On Dirty when a character is entered or deleted in a control

On Change when the data in a control is updated

On Got Focus when the control gets the focus from another form or control

On Lost Focus when the control loses the focus to another control or form

On Dbl Click by clicking and releasing the primary mouse button twice on the control

On Mouse Down by clicking the mouse button while the mouse pointer is on a control

On Mouse Up by releasing the mouse button while the mouse pointer is over the control

On Mouse Move by moving the mouse pointer over a control

On Key Down by pressing any key on the keyboard when a control has the focus or is using a SendKeys macro

On Key Up by releasing a key or immediately after running the SendKeys macro

On Key Press by pressing and releasing any key on the keyboard when on a control that has the focus or when using a SendKeys macro

On Enter when the control first receives the focus from another control on the same form

On Exit when the control loses the focus to another control on the same form

On Undo

when a control is returned to its original state by clicking the Undo

Field/Record button, clicking the Undo button, pressing the ESC key. Does not trigger on using the CTRL z keystroke.

Page 176: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 171

You can see the events associated with a form or report object by selecting the object in Design or Layout View, opening the Property Sheet and viewing the Events tab. The list below gives events for a form itself.

Event Property Action is initiated

OnActivate when a form receives the focus and becomes the active window.

AfterDelConfirm after the user confirms the deletions and the records are actually deleted or when the deletions are cancelled

AfterFinalRender after all elements in the specified PivotChart view have been rendered

AfterInsert after a new record is added

AfterLayout after all charts in the specified PivotChart view have been laid out, but

before they have been rendered

AfterRender after the object represented by the chartObject argument has been rendered

AfterUpdate after changed data in a control or record is updated

OnApplyFilter when a filter is applied to a form

BeforeDelConfirm after the user deletes to the buffer one or more records, but before Microsoft Access displays a dialog box asking the user to confirm the deletions

BeforeInsert the user types the first character in a new record, but before the record is actually created

BeforeQuery the specified PivotTable view queries its data source

BeforeRender before any object in the specified PivotChart view has been rendered

BeforeScreenTip before a ScreenTip is displayed for an element in a PivotChart view or PivotTable view

BeforeUpdate before changed data in a control or record is updated

OnClick when the user presses and then releases a mouse button over an object

OnClose when a form is closed and removed from the screen

OnCommandBeforeExecute before a specified command is executed. Use this when you want to impose certain restrictions before a particular command is executed

OnCommandChecked when the specified Microsoft Office Web Component determines whether the specified command is checked

OnCommandEnabled when the specified Microsoft Office Web Component determines whether the specified command is enabled

OnCommandExecute after the specified command is executed. Use this when you want to execute a set of commands after a particular command is executed

OnCurrent when the focus moves to a record, making it the current record, or when the form is refreshed or requeried

Page 177: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 172

OnDataChange when certain properties are changed or when certain methods are executed in the specified PivotTable view

OnDataSetChange whenever the specified PivotTable view is data-bound and the data set changes — for example, when a filter operation takes place. This also occurs when initial data is available from the data source

OnDblClick when the user presses and releases the left mouse button twice over an object within the double-click time limit of the system.

OnDeactivate when a form loses the focus to a Table, Query, Form, Report, Macro, or Module window, or to the Database window.

OnDelete when the user performs some action, such as pressing the DEL key, to delete a record, but before the record is actually deleted

OnDirty when the contents of the specified control changes

OnError when a run-time error is produced in Microsoft Access when a form has the focus

OnFilter when the user opens a filter window by clicking Filter by Form, Advanced Filter/Sort, or Server Filter By Form

OnGotFocus when the specified object receives the focus

OnKeyDown when the user presses a key while a form or control has the focus. This

also occurs if you send a keystroke to a form or control by using the

SendKeys action in a macro or the SendKeys statement in Visual Basic

OnKeyPress when the user presses and releases a key or key combination that corresponds to an ANSI code while a form or control has the focus. This also occurs if you send an ANSI keystroke to a form or control by using the SendKeys action in a macro or the SendKeys statement in Visual Basic

OnKeyUp when the user releases a key while a form or control has the focus. This also occurs if you send a keystroke to a form or control by using the SendKeys action in a macro or the SendKeys statement in Visual Basic

OnLoad when a form is opened and its records are displayed

OnLostFocus when the specified object loses the focus

OnMouseDown when the user presses a mouse button

OnMouseMove when the user moves the mouse

OnMouseUp when the user releases a mouse button

OnMouseWheel when the user rolls the mouse wheel in Form View, Split Form View, Datasheet View, Layout View, PivotChart View, or PivotTable View

OnConnect when the specified PivotTable view connects to a data source

OnDisconnect the specified PivotTable view disconnects from a data source

OnOpen when a form is opened, but before the first record is displayed

Page 178: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 173

OnPivotTableChange whenever the specified PivotTable view field, field set, or total is added or deleted

OnQuery whenever the specified PivotTable view query becomes necessary. The query may not occur immediately; it may be delayed until the new data is displayed

OnResize when a form is opened and whenever the size of a form changes

OnSelectionChange whenever the user makes a new selection in a PivotChart view or PivotTable view

OnTimer for a form at regular intervals as specified by the form's TimerInterval property

OnUndo when the user undoes a change

OnUnload after a form is closed but before it's removed from the screen. When the form is reloaded, Microsoft Access redisplays the form and reinitializes the contents of all its controls

OnViewChange whenever the specified PivotChart view or PivotTable view is redrawn

ASSIGNING A MACRO TO A FORM OR REPORT CONTROL

EVENT PROPERTY

Discussion

You can associate a macro with a control on a form or report using the Event properties of the control. An event is an action, such as a mouse click or a change in value that can initiate a response. The macro runs automatically when the specified event involving that control occurs.

Many events involve the control having the focus. Focus means that the control can receive data from mouse clicks or keyboard actions. For example, field boxes, toggle buttons, and radio buttons can have the focus, since they can respond to data entry from the keyboard or mouse. Only one control can have the focus at a time.

By linking a command button or a control with a macro, you can make commonly used functions easier. Initiating macros this way is particularly useful because it does not require the user to know or use the Access Ribbon. For example, you could associate a macro with a command button on a form to print a report. The user could then print the report by clicking the command button, without having to open the report or know the correct Ribbon commands.

Procedure

1. Open the desired form in Design or Layout view.

2. Click the control you want to assign a macro to.

3. If necessary, click the Property Sheet command on the Design tab (Design View) or the Arrange tab (Layout View).

Page 179: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 174

4. In the Property Sheet, click the Event tab.

5. Select the required event.

6. Use the list arrow to select the macro you want to use.

7. If required, close the Property Sheet. When the form is viewed, carrying out the relevant event on the designated control will run the macro.

Tip You can quickly open or close the Property Sheet by pressing F4.

Assigning a macro to a form’s Before Update property

ASSIGN A MACRO TO A FORM COMMAND BUTTON

Discussion

Command buttons are controls to which you can assign actions. They are often used to run macros on a form or report. You can place descriptive text or a picture on a command button so that the user can easily identify the purpose of the button.

You create a command button in Design or Layout View using the Button command in the Controls group under Form(Report) Design(Layout) Tools. After you create the command button on the form, you set an event properties (usually the On Click event) to initiate the action and use additional properties to add text or a picture on the button.

To create a command button in which a macro will be attached, it is recommended that you disable the Control Wizards button in the toolbox.

Procedure

1. Open the required form or report in Design or Layout View.

2. Select the Design tab under Form (Report) Design (Layout) Tools.

3. In the Controls group, click the Button button .

4. Click on the form or report where you want the button located.

Page 180: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 175

5. Click Cancel in the Command Button Wizard.

6. If necessary, open the Property Sheet (press F4).

7. Select the Event tab.

8. Select the required property (usually OnClick).

9. Click the drop down list arrow and select the required macro.

10. Click the All tab.

11. In the Caption box, enter the text to be displayed on the button.

12. If necessary, close the Property Sheet (press F4).

13. View the form.

14. When clicked, the button in the form will run the macro.

Assign a macro to a command button’s OnClick event

Alternatively, if you simply wish to assign a macro to the OnClick property

1. Open the required form in Design or Layout View.

2. Select the Design tab under Form (Report) Design (Layout) Tools.

3. In the Controls group, click the Button command .

4. Click on the form where the button is to be located.

5. Click Miscellaneous in the Categories: list of the Command Button Wizard.

6. Click Run Macro in the Actions: list.

7. Click Next.

8. Select the macro you want to assign to the command button.

9. Click Next.

10. Select the Text option.

11. Type the text that you want to display on the button (eg. the name of the macro that the button runs).

12. Click Next.

Page 181: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 176

13. Enter a name for the button or accept the default name.

14. Click Finish.

Form in Design View showing command button

CREATING A MACRO DIRECTLY FROM A FORM/REPORT

CONTROL EVENT PROPERTY

Discussion

You can create a macro for an event property directly in Form (Report) Design (Layout) View. By clicking the ellipsis button alongside the relevant event, you can open the Macro Builder and create a macro to associate with the event.

Associating a macro with a form object is used when you wish a macro to run automatically, for example, when the user clicks into a text box to edit data or when a form opens or closes.

Creating a macro using this method requires that you assign a macro to an “event”, such as

On Click or On Close. When you select an Event property, the Build button appears . The Build button then gives you access to the Macro Designer which it calls Macro Builder.

Page 182: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 177

NB: If creating a macro for a form or a report using the above method, the macro becomes "embedded" and does not appear in the Macro section of the navigation pane in the same way as a "named" macro that you create from scratch.

If the macro needs to be edited, therefore, you have to open it by opening the form or report first, selecting the object it has been assigned to, clicking in the Property Sheet the event that the macro has been assigned to, and then clicking the Build button to open the macro code in Design View.

Procedure

1. Open the required form or report in Design or Layout View.

2. Select the object you want to associate a macro with, eg. a text box.

3. Select the Design tab under Form (Report) Design (Layout) Tools.

4. In the Tools group, click the Property Sheet command .

5. In the Property Sheet, select the Event tab.

6. Select the desired Event property.

7. Click the Build button .

8. In the Choose Builder dialog box, click Macro Builder.

9. Click the OK button.

10. Create the macro as described in the previous lesson.

11. Save and name the macro. The macro is now linked to the object and will run when that event occurs.

Page 183: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 178

Tip By default, Access 2010 hides certain Actions in the Macro Designer. To see them all, click the Show All Actions command in the Show/Hide group of the Macro Tools tab.

Tip

If the macro that you want to associate with a control event already exists, simply select it from the drop-down list of the relevant event in the Properties Pane.

Tip You can quickly open or close the Property Sheet by pressing F4.

ADDING A SIMPLE IF CONDITION TO A MACRO

Discussion

You can add conditional expressions (condition) to macro actions. Conditions act like a filter, allowing macro actions to be performed only when the condition is true.

To add a condition to a macro, in the Macro Designer, you add an IF block to the Code

Sheet. This can be done by double clicking the IF Program flow item in the Actions Catalog. The IF block provides two boxes; the first box is where you enter the conditional expression and the second box beneath it is where you enter the action that you want the macro to perform if the conditional expression evaluates to TRUE. If the condition is FALSE, Access does not perform the action but continues reading down the Code Sheet for whatever comes next.

In the example below, the Set Value action is only performed if the SalesAmount field contains a value greater than 500. In other words, the macro will enter a value of 15% (0.15) in the Discount field if the SalesValue field is over 500.

The Add New Action drop down list below the End If is optionally used for any subsequent actions that you want performed irrespective of whether the condition above is TRUE or FALSE.

Page 184: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 179

If you want more actions performed if the condition is True, you select them from the Add New Action drop list before the End If. In the example below, not only does the macro populate the Discount field with 15% if the SalesValue is over 500, but it also displays a message box confirming this.

When entering a conditional expression, there are certain rules you must follow when referring to controls in tables, queries, forms, and reports. All references must be separated with an exclamation mark. Additional rules for the database objects and controls are listed in the following table:

Controls Rules

Controls in tables

Enclose the name of the table and the name of the control in square brackets and separate them with an exclamation point. For example, [Orders]![Customer ID] refers to the Customer

ID field in the Orders table.

Controls in queries

Enclose the name of the query and the name of the control in square brackets and separate them with an exclamation point. For example, [Order Items]![Item Number] refers to the Item

Number field in the Order Items query.

Controls in forms

Enclose the name of the form and the name of the control in square brackets and separate them with an exclamation point. Indicate that you are referring to a form by beginning the statement with the word Forms. For example,

Conditional expression

Action to perform if condition is TRUE

End of the IF THEN block

Subsequent actions to perform irrespective of whether the condition above is TRUE or FALSE

Conditional expression

First action to perform if condition is TRUE

End of the IF THEN block

Subsequent actions to perform irrespective of whether the condition above is TRUE or FALSE

Second action to perform if condition is TRUE

Page 185: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 180

Forms![Customers]![Customer ID] refers to the Customer ID field in the Customers form.

Controls in reports

Enclose the name of the report and the name of the control in square brackets and separate them with an exclamation point. Indicate that you are referring to a report by beginning the statement with the word Reports. For example, Reports![Customer Sales]![Contact Name] refers to the Contact Name field in the Customer Sales report.

Procedure

1. Open the required macro in Design View.

2. Double click IF under Program flow in the Action Catalog .

3. Enter a valid conditional expression in the If box. Refer to the following topic for how to use the Builder to help create the expression.

4. Click the Add New Action drop down list or navigate to an action under Actions in the Actions Catalog.

5. Select an action for the macro to perform where the conditional expression created in step 3 above is TRUE.

6. Add any necessary arguments to the action.

7. Continue adding more actions and/or more If blocks, if necessary.

8. Save, close and test the macro.

USING THE EXPRESSION BUILDER TO HELP CREATE

CONDITIONAL EXPRESSIONS

Discussion

Conditional expressions are essentially calculations that result in TRUE or FALSE (Boolean). They can include database objects, operators and values. Objects range from table fields to controls in a form. Operators are standard mathematical operators used in calculations (such as +, -, *, /, (), <>). Values can be numbers, dates, text, and built-in functions, as well as field, control, and property identifiers.

You can create a conditional expression using the Expression Builder. The Expression

Builder is opened by clicking the button at the right of the Conditional expression box.

Page 186: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 181

The Expression Builder displays the Expression box in its top pane, a row of operator buttons below the Expression box, and three lower panes that display categories, subcategories, and values, respectively.

The Expression Builder

You can use a combination of methods to build a new expression. You can type some elements of the expression and select others (such as operators, functions, and values) from the Expression Element/Categories and Values panes. If you make a mistake, you can select and delete any elements that you want to remove from the Expression box.

When typing certain elements of an expression, “Intellisense” tries to predict the text and offers a list of options to choose from. This can speed up entering an expression and prevent spelling errors.

“Intellisense” predicting field names from a table

The Expression Builder is available in the Macro Designer not just for helping you with conditional expressions but also for helping you set up actions arguments. “Intellisense” also activates as you type expressions directly into an action argument for example, it you type a table, field name or function.

“Intellisense” predicting a field name in an action argument.

Page 187: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 182

Procedure

1. Click the button to invoke the Expression Builder.

2. Expand the Expression Elements pane as necessary.

3. Click the required element.

4. Click the required subcategory in the Expression Categories pane.

5. Double click on a value in the Expression Values pane to insert it in the Expression box.

6. Click OK.

Alternatively, to enter an expression manually

1. Invoke the Expression Builder as described above.

2. Select existing text or position the insertion point as needed in the Expression box.

3. Type the required value making use of “Intellisense” to help with correct syntax and spelling of objects, fields, operators and function arguments.

4. Complete the expression.

5. Click OK.

Tip

You can add existing actions inside an If block by selecting them (select the first one and then hold down the[SHIFT] or [CTRL] key as you select others) and then right clicking anywhere on the selected area and selecting Make If Block.

ADDING ADVANCED IF CONDITIONS TO A MACRO

Discussion (Else)

The IF examples given previously in this lesson carry out actions if the conditional expression is TRUE. There may be cases, however, where you want alternative actions performed by the macro if the condition is not TRUE (ie. FALSE).

This is achieved by adding Else to the IF block. Actions entered under Else will be performed by the macro in all cases where the Conditional expression evaluates to FALSE. Else is added to the code block by clicking Add Else at the bottom right of the IF code block.

In the example below, the macro populates the Discount field with a value of 15% (0.15) where the SalesValue field is greater than 500 but in all other cases (viz. 500 or less) the Discount field is populated with a value of 5% (0.05).

Page 188: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 183

As in the case of the simple If block described in a previous topics, there can be more than one action performed under Else.

Discussion (ElseIf)

ElseIf can be added to the If code block to carry out a second test if the first one is FALSE hence, producing a third possibility for action(s). You can add as many ElseIfs to an If block as you wish, potentially giving you multiple possibilities for different actions.

Else If is added to the If code block by activating the If code block and clicking Add Else If at the bottom right of the actions section. Add Else If appears at the bottom right not only of the first If conditional expression actions, but also at the bottom right of any subsequently added Else If actions.

Conditional expression (Start of IF block)

Actions to perform if condition is TRUE

End of IF block

Subsequent actions to perform irrespective of whether the condition above is TRUE or FALSE

Action to perform if condition is FALSE

Page 189: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 184

Like the simple If block described earlier, an If block using ElseIf(s) can be used with or without an Else.

A common example of this is where you wish to evaluate text. Let us say that you wish to speed up data entry so that when a user enters the name of a city into a record, a macro automatically enters the country for that city in the Country field. The completed macro would look as follows (only four cities are used to keep the example concise and clear):

Another common use for ElseIf is where there is a need to evaluate numerical values on a sliding scale. Let us say that you offer three rates of discount to your customers: 15% where the sale value is over 500; 5% where the sale value is over 200 (ie. between 200 and 501) and 2% in all other cases (ie. where the sale value is 200 or less). You would eliminate the possibilities by carrying out conditional expressions in a descending order; the first condition would test for sales value that were over 500 and the second test (the Else If) would test for sales values that were over 200. The Else at the end of the If block would, logically, cover whatever had not been eliminated above, ie. 200 or less. The completed macro would look as follows:

Page 190: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 185

NB: An If code block only carries out one set of actions, viz. the ones associated with the first conditional expression found that evaluates to TRUE.

Hence, when using ElseIf to test ranges of values (as in the example above), it is important to list the conditional expressions so that they eliminate values in a descending order. If, for example, the first conditional expression above tested for values greater than 200, any sales value that was over 500 would still only get a 5% discount.

Procedure

1. Open the required macro in Design View.

2. Double click IF under Program flow in the Action Catalog .

3. Enter a valid conditional expression in the If box. Refer to the previous topic for how to use the Builder to help create the expression.

4. Click the Add New Action drop down list or navigate to an action under Actions in the Actions Catalog.

5. Select an action for the macro to perform where the conditional expression created in step 3 above is TRUE.

6. Add any necessary arguments to the action.

7. Continue adding more actions, if necessary.

8. At the bottom of the actions section, click Add Else If or Add Else.

Actions to perform if 1st condition is TRUE

1st conditional expression; identify if sales value is over 500.

Action to perform if 1st condition is TRUE

End of IF block

Subsequent actions to perform irrespective of whether the condition above is TRUE or FALSE

Action to perform under all other circumstances, ie. where sale value is NOT greater than 500 nor greater than 200, ie. 200 or less.

2st conditional expression to be performed ONLY if the previous one is FALSE; identify if sales value is over 200.

Action to perform if 2nd condition is TRUE

Page 191: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 186

9. If you have clicked Add Else:

a. Click the Add New Action drop down list below the Else.

b. Select an action for the macro to perform where the conditional expression created in step 3 above is FALSE.

c. Add any necessary arguments to the action.

d. Continue adding more actions under Else, if necessary.

10. If you have clicked Add Else If:

a. Enter a second, valid, conditional expression in the Else If box. Refer to the previous topic for how to use the Builder to help create the expression.

b. Click the Add New Action drop down list below the Else If conditional expression.

c. Select an action for the macro to perform where the conditional expression created in step 10a above is TRUE.

d. Add any necessary arguments to the action.

e. Continue adding more actions, if necessary.

f. At the bottom right of the actions section, click Add Else If if a conditional expression is required to eliminate another possibility and proceed as described in steps 10a to 10f. If not, you can:

i. leave the If block as is;

ii. click Add Else at the bottom right of the last Else if and follow steps 9a to 9d above.

11. In all cases save, close and test the macro.

Tip

You can add existing actions inside an If block by selecting them (select the first one and then hold down the [SHIFT] or [CTRL] key as you click others) and then right-clicking anywhere on the selected area(s) and selecting Make If Block from the shortcut menu.

CREATING SUBMACROS

Discussion

Creating submacros means placing multiple macros on the same macro sheet and saving them with a single name. This has several advantages; the most obvious being that it reduces the number of macros that appear in the Navigation Pane. More importantly, it allows you to organise your macros by keeping related macros together on one single macro sheet. For example, if you have several macros relating to a form that is designed to view and manage Orders taken, you can store all of them together in one code sheet and save it, for example, as OrderFormMacros. Alternatively, you could organise all your form macros and all your report macros as submacros into two main macros named FormMacros and ReportMacros.

To use submacros, you refer to them with the name of the main macro, followed by a full

stop, and then the submacro name, ie. MainMacroName.SubMacroName

Page 192: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 187

When giving a name to a submacro you should make sure that the name is descriptive enough to indicate its contents. This helps you remember - and other users know - what the macro does. For example, if all the submacros relate to an Orders form, you could save them in a main macro named OrderFormMacros. It is usual practice to omit spaces from macro and submacro names.

The example below shows three submacros stored together on a single macro sheet that has been saved with the name OrderFormMacros.

Three submacros on a single macro sheet saved with a single name

When using the above macros (eg. assigning them to a Quick Access Toolbar button, to a command button on a form/report, or to an event), you would to refer to them as:

Order Form Macros.EnterDiscount

Order Form Macros.ShowProductList

Order Form Macros.PrintInvoice

Tip

If you have already created separate macros, you can combine them into one main macro by cutting (or copying) and pasting their code blocks into a new macro sheet, selecting the blocks, right-clicking the selected area and clicking Make Submacro Block from the shortcut menu.

Procedure

1. Select the Create tab on the Ribbon.

2. Click Macro in the Macros & Code group .

3. Double-click Submacro under Program flow in the Actions Catalog pane or select Submacro at the top of the Add New Action drop down list.

Page 193: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 188

4. In the Submacro box, enter a name for the submacro.

5. In the submacro block, proceed as described in previous procedures to create the necessary actions for the submacro to perform.

6. To create further submacros on the same macro sheet, repeat steps 3 to 5 above.

7. Save and close the macro as normal. To use the submacros, refer to them with the name of the main macro, followed by a full stop, and then the submacro name, ie.

MainMacroName.SubMacroName

Saving submacros

HANDLING ERRORS IN A MACRO

Discussion

When it Access encounters an error during the execution of a macro, it normally produces a default response, viz. an error message followed by an Action Failed or Macro Single Step dialog box. You can, however, produce a more user-friendly way of handling errors in your macros by using the OnError action.

The OnError action is usually placed at the beginning of a macro, but can be placed later. The action will trigger if an error (runtime) occurs when that macro is executed.

Page 194: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 189

Example of default runtime error windows

Example of a custom error handling message

using the OnError action

OnError has the following arguments:

Argument Option Description

GoTo Next Access records the details of the error in the MacroError object but does not stop the macro. The macro ignores the error and continues with the next action.

In some cases, this means that the macros will still execute correctly but in others, the macro may do nothing at all!

Macro Name

Access stops the current macro and runs the macro that is named in the Macro Name argument.

Fail

Access stops the current macro and displays an error message in the same way it would if there were no OnError action in the macro (displays default message and a Macro Single Step or Action

Failed dialog box).

The main use for the Fail setting is to turn off any error handling that you established earlier in a macro.

MacroName (only used if GoTo argument is set to Macro Name)

If the Go to argument is set to Macro Name, type the name of the macro to be used for error handling. This macro must exist as a Submacro (see page 186) in the same macro as the OnError action.

Page 195: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 190

Procedure

1. Create a new macro or open an existing one in Design View.

2. At the top of the code sheet, add an OnError action.

3. Click the GoTo argument drop down list.

4. Select an option (refer to the table above). If selecting Macro Name, ensure that you have a Submacro with that name on the same code sheet that executes the required actions.

5. Save and close the macro design.

Examples

The sample code below displays a simple custom message if the macro encounters an error during execution.

Different errors generate different error numbers for example, if a macro action opens a form and that form is not found, the error number 2102 is generated. These error numbers are recorded by Access while the macro is running, in the [MacroError].[Number] property. Normally, these numbers can be seen in the bottom right of the Macro Single Step or Action Failed dialog box.

In some cases, therefore, it is possible to “trap” different errors using their number. The sample code below uses an IF to test the error number and produces a message explaining the problem if the error was caused by number 2102, but produces a more generic message if any other error is encountered:

Initiates custom error handling

Main macro code that might generate an error, eg. the form is not found

Sub macro that is “called” (takes over) if an error occurs.

Page 196: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 191

The following sample text can be used as a message argument to a message box. As well as returning static text in the message box, it also returns the error number and error description. The ampersands ( & ) are “concatenation” characters used for joining together text, variables and constants. Chr(13) is a special function that simulates a paragraph break in the text.

="There has been an error. Please call IT support on Extn: 2331" & Chr(13) & "quoting the following number and description: " & Chr(13) & Chr(13) & [MacroError].[Number] & " " & [MacroError].[Description]

USING GROUPS IN MACROS

Discussion

For readers who are familiar with creating macros in previous versions of Access, Groups in Access 2010 macros are not the same thing as Group Macros. To create Group Macros (as they were called in previous version of Access) refer to the topic above about Submacros.

Groups in Access 2010 are purely used to organise long macros into structured sections that can be collapses and expanded, thus making the code sheet easier to read and understand. The example below shows how the code has been broken down into three groups to clarify

Initiate custom error handling

Main macro code that might generate an error, eg. the form is not found

Sub macro that is “called” (takes over) if an error occurs.

Page 197: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 192

the actions and logic. You cannot add Submacros to a group although you can create groups within submacros.

Macro code sheet split

into Groups (expanded)

Same macro code sheet

with Groups collapsed

Procedure

1. Create a new macro or open an existing macro in Design View.

2. If starting from new:

a. Double click Group under Program flow in the Actions Catalog or select group from the Add New Action drop down list.

b. In the Group: text box, enter a descriptive name for the group.

c. In the group block, create code as described in previous procedures. You cannot create Submacros in a Group.

d. Repeat steps 2a to 2c for other groups of code that you wish to create

3. If wishing to add groups to an existing macro:

a. Select the first code block that you wish to be part of a group.

b. Hold down the [SHIFT] key and click the adjoining code blocks that you want to be part of the same group.

c. Right-click the block at the top of the selection.

d. Select Make Group in the shortcut menu.

Page 198: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 193

e. Type a descriptive name for the group.

f. Repeat steps 3a to 3e for other groups that you wish to create.

g. If necessary, create new groups in the existing macro by following steps 2a to 2c above.

4. In all cases, save and close the macro design.

CREATING AN AUTOEXEC MACRO

Discussion

While you can select a command to run a macro, you can also have a macro that runs automatically when a database is opened. This type of macro is called an Autoexec macro because it is automatically executed when the database is opened and can be used to automate or simplify the database for other users.

You can create an Autoexec macro in two ways. You can rename an existing macro Autoexec, or you can create a new macro and save it with the name Autoexec. Since the Autoexec macro is stored with the database, each database can have its own Autoexec macro. However, you can only have one Autoexec macro per database.

When necessary, you can bypass the Autoexec macro by holding the [Shift] key while you open a database.

Procedure

1. To create an Autoexec macro by renaming an existing macro, first display the Macros list in the Navigation pane.

2. Right click the macro you want to rename.

3. Select Rename in the shortcut menu.

4. Type Autoexec.

5. Press [Enter].

6. The next time that database is opened the macro will run automatically.

Alternatively

1. Follow the procedure on page 154 for creating a new macro.

2. Save the macro with the name, Autoexec.

3. Close the macro design window.

Tip

By default, Access 2010 initially hides certain Actions. To see them all, click the Show All Actions command in the Show/Hide group of the Macro Tools tab.

Page 199: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 194

MACRO EXAMPLES

Ensuring Correct Data Entry

By using a conditional macro (see page 178), a field can be tested to see if the correct value has been entered. Although this can be done using Validation Rules in Table Design, using a macro offers greater scope and flexibility on how the incorrect data entry is handled. For example, by using the Message Box action, a custom message can be created to warn the user of the problem. That can then be followed by a form opening and listing additional information to assist the user with correctly completing the data entry.

Finding the appropriate event to attach a macro is an important factor to take into account. If the macro to check the value entered was attached to the On Exit property of the field, it would not check the fields contents if the fields was skipped over by the user. Instead if the macro was attached to the Before Update property of the form it will always check the contents of the field before the record is saved.

Below is some sample code for cancelling data entry if a figure over 5000 is entered in the credit limit field of a customer form, and then opening another form of additional information. This macro would be assigned to the credit limit control’s BeforeUpdate event.

1. Open the form in Design View or Layout View.

2. If necessary, click the Property Sheet command in the Design tab under Form (or Layout) Design Tools.

3. On the form, click the object that you wish to assign the macro to.

4. In the Property Sheet, select the Event tab.

5. Click in the Before Update property.

6. Click the Build… button .

7. In the Choose Builder box, select Macro Builder.

8. Click OK, the Macro Designer opens.

9. Create the following code referring to procedures in previous topics for detailed instructions.

Page 200: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 195

10. When the form is open and the designated field is filled incorrectly, the user will be stopped from saving the entry in the field until the discrepancy is rectified or [ESC] is pressed to leave any existing data unchanged.

NB: Alternatively, a macro can be created first and then attached to the required event property.

Tip You can quickly open or close the Property Sheet by pressing F4.

Tip

By default, Access hides certain items in the Action column. To see them all, click the Show All Actions command in the Show/Hide group of the Macro Tools tab.

Tip

Because the macro created as described above is an "embedded" macro, it does not show in the Macro section of the Navigation Pane. To edit it you have to

open it Form Design View by clicking the Build button next to event property that it has been assigned to.

Automatically Filling Fields

By using a conditional macro, fields can be automatically filled on a form depending upon the value of another field. The check on the contents of the field can be carried out after the data has been entered into the field and the user presses tab or enter to move onto the next field. Thus by assigning a conditional macro to the OnExit property to the field another field can be conditionally filled depending upon the value of the first field.

By using the SetValue action in a macro, a control’s contents (value) or properties can be set. Then, using the GoTo control action, the set control can be bypassed. The example below creates a macro designed to automatically enter a country into the Country field of a form based on the city that is entered in the City field. Because it is then not necessary for the user to enter data in the Country field, the macro automatically moves the focus to next relevant field.

Procedure

1. Open the form in Design View or Layout View.

On exiting the City field (press Tab or Enter), Italy is automatically entered in the Country field and the PostCode field is selected

Page 201: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 196

2. If necessary, click the Property Sheet command in the Design tab under Form

(or Layout) Design Tools.

3. On the form, click the object that you wish to assign the macro to.

4. In the Property Sheet, select the Event tab.

5. Click the On Exit property.

6. Click the Build… button .

7. In the Choose Builder box, select Macro Builder.

8. Click OK, the Macro Designer opens.

9. Create the following code referring to procedures in previous topics for detailed instructions.

10. When the form is open and a city name is entered in the City field, upon exiting the City field the country field will be automatically populated. The focus then passes to the next relevant field - PostCode.

NB: Alternatively, a macro can be created first and then attached to the required event property.

Tip To see the SetValue action in the macro builder, you MUST click the Show All Actions command in the Show/Hide group of the Macro Tools tab.

Tip You can quickly open or close the Property Sheet by pressing F4.

Page 202: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 197

EXERCISE

A. Using a condition in a macro

1. Open Train16.

2. Create a macro that will not allow the record to be saved unless a value greater than 0 is entered in the Amount Paid field, and then returns the user to the Amount Paid text box. Use the table below as a guide; the screenshot lower down shows the solution if you get stuck:

If Condition Action if TRUE (Then)

Arguments

[Amount Paid] <=0 CancelEvent

MessageBox Message: A value over 0 must be entered in this field before the record can be saved. Click OK and enter a value or press ESC to cancel updating this record.

GoToControl Control name: [Amount Paid]

3. Close the Macro Designer and save the macro as CheckPaid.

4. Open the Payments Form in Design View.

5. Assign the macro to the form’s BeforeUpdate event property.

6. Save and them view the form.

7. Add a new record as follows:

Project ID: 1023

Payment Date: 06/06/1995

Amount Paid: 0

Balance Due: 200

Page 203: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 198

8. Move to the next new record. At this point, Access tries to update the record but before doing so, the macro runs and stops the update.

9. Enter a value of 100 in the Amount Paid text box.

10. Move to the next new record. This time, the macro allows the update to take place.

11. Close the form.

12. Close the database.

B. Further conditional macros

1. Open Train17. This database uses overlapping widows instead of tabbed documents.

2. Rename the Open Payment/Invoice macro to Autoexec. Make sure that you press [Enter] after you rename it. Close the database and reopen it to test the macro. Notice that the two form windows open. Close the form windows.

3. The Balance macro opens a message box warning that there is a balance due for the project.

4. Open the Payment form in Design view.

5. Select the Balance Due bound (text box) control.

6. Open the Property Sheet, if necessary.

7. Assign the Balance macro to the OnGotFocus event.

8. Close and save the form.

9. View the Payment Form. Click the Balance Due text box. Notice that a message box opens. Close the message box. Move through the next several records and notice that the message box opens whether or not there is a balance due.

10. Close the form.

11. Open the Balance macro in the Macro Designer.

12. Edit the macro by adding an If condition so that the message box only displays when the balance due is greater than 0 (Hint: Enter the following If condition for the macro: [Balance Due] > 0). Refer to the screenshot lower down this page if you need help.

13. Close the Macro Designer and save the changes.

14. Open the Payment Form in Form view. Click the Balance Due text box. Notice that a message box opens for the first record because there is a balance due (a balance greater than 0). Move through the next several records and notice that the message box only opens when a balance is due. Close the form.

15. Open the Project form in Design view.

Page 204: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 14 – Further Macros

WWP Training Page 199

16. Assign the View Report macro to the Print Report command button so that it runs when the mouse button is clicked.

17. Close and save the Project Form. Open the Project Form in Form view and test the Print Project Report command button.

18. Close the form and the report.

19. Open the Macro Designer.

20. Create three submacros with the following details. Use the screenshot lower down this page if you need help:

Submacro name Action Argument(s)

OpenProjectForm OpenForm Form Name: Project Form

PrintCIReport OpenReport Report Name: Client Information Report View: Print Preview

OpenTrainerTable OpenTable Table Name: Trainer

21. Save the macro as Client Macros and close the Macro Designer.

22. Open the Project Form in Design View.

23. Create three command buttons at the right hand side of the form to run the submacros created above. Try assigning the macros to the OnClick event property of each button without using the Wizard and use a caption of your own choosing.

24. Save and view the form.

25. Test then three Client Macros.

26. Close all open objects and then close the database file.

Page 205: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 200

LESSON 15 - USING SWITCHBOARDS

In this lesson, you will learn how to:

Open and use a switchboard

Create a switchboard from a blank form

Use the Switchboard Manager

Manage a switchboard on a database with overlapping windows

Open a switchboard automatically

Page 206: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 201

INTRODUCTION

Discussion

In Access, a switchboard is a form that allows users of a database to get from one place to another or perform several commands from a central location.

If a database has a switchboard, it is usually the first item the user sees when the database is opened. While a simple database may have one switchboard, a database with many forms and reports may have several switchboards.

A switchboard is basically a form that is not bound to a table or a query. It contains command buttons or other objects that run macros in response to an action by a user.

Creating a switchboard should be one of the last things you do when creating a database. You may want to consult with the people who use the database, or let them use it without a switchboard for a while, so that you can get a better idea of what needs to be automated. There are several ways to create a switchboard, eg. start with a blank form from scratch or, use the Switchboard Manager.

When you create a form from scratch to be used as a switchboard, it should not be bound to a table or query. To ensure that the switchboard does not look or work like a form, you need to set certain properties, such as not displaying navigation buttons and scroll bars. Creating a switchboard using a blank form requires that you add your own command buttons, controls, and graphics, as well as set the desired form properties.

The Switchboard Manager automates the process of making or editing a switchboard. It allows you to make a switchboard the default switchboard so that it appears on startup or branch to other switchboards. When a switchboard is created using the Switchboard Manager, Access creates a table that describes what the buttons on the form display and do.

CREATING A SWITCHBOARD FROM A BLANK FORM

Discussion

Before creating the switchboard form, you should have an idea what needs to be included. If you are going to use macros to initiate certain actions, you should create them before you start creating the switchboard.

Once you have created the basic switchboard form, you add controls, such as command buttons, to it. As your database changes, you can modify the switchboard, as necessary. To

Page 207: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 202

improve the appearance of your switchboard, you can add labels and graphics, change object colours and fonts, and modify other form properties.

If a control performs a single function, such as opening a form or printing a report, and the form or report already exists, you can add the control using the Control Wizards. If the form or report has not been created, you can create the control without using the Control Wizards. Then, after the form or report is created, you can assign an action to the control and change any other properties, as desired.

Procedure

1. Open the desired database.

2. Select the Create tab.

3. Click the Blank Form command .

4. Select the Design tab under Form Layout Tools.

5. Click the lower half of the View command .

6. Select Design View. Although Layout view is adequate for creating a switchboard, Design View gives you greater ease and flexibility with adding, moving and sizing controls.

7. Click the Label command in the Controls group.

8. Draw a label at the top of the form.

9. Enter a name for the switchboard.

10. Format the label with font and colour properties as desired. Use the screenshot in the Discussion above as a guide to what is required.

11. Add command buttons to the form to run macros for opening forms, running queries, printing reports and carrying out any other database tasks that may be required. See page 174 for detailed procedure on assigning macros to command buttons.

12. Use commands in the Controls group of the Design tab to add any additional embellishments (eg, pictures, logos, frames) to enhance the appearance of the form.

13. Use commands in the Home tab to format the form with colours and font attributes.

14. Save the form (suggest naming it Switchboard) and close it.

Tip A quick way to add a control to a switchboard is to open the switchboard in Design View and drag a macro to it. When you create a control this way, the control action is automatically assigned the On Click event property.

USING THE SWITCHBOARD MANAGER

Discussion

The Switchboard Manager automates the process of making or editing a switchboard. It allows you to make a switchboard the default switchboard so that it appears on startup or

Page 208: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 203

branch to other switchboards. When a switchboard is created using the Switchboard Manager, Access creates a table that describes what the buttons on the form display and do.

The Switchboard Manager command is not displayed on the Ribbon by default, it has to be added. The procedure below describes adding it to the Quick Access Toolbar.

Procedure

1. Open the desired database.

2. Click the Customize Quick Access Toolbar drop down arrow at the right of the

Quick Access Toolbar .

3. Click More Commands….

4. Select All Commands in the Choose commands from: drop down list.

5. Scroll down the commands list and select Switchboard Manager

.

6. Click Add >> .

7. Click OK. The command is added to the Quick Access Toolbar.

8. Click the Switchboard Manager command.

9. Click the Yes button if asked to create a switchboard.

10. In the Switchboard Manager box, click the Edit… button.

11. In the Switchboard Name: box, type a name for the main page.

12. Click the New… button.

Page 209: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 204

13. Enter text for the first command button that you want the switchboard to contain..

14. In the Command: box, click the drop down arrow.

15. Select a command.

16. If in step 15 you have selected an command to display a form, report or run a macro/module, a drop down box will appear below the Command: box. Select in this list the object in question.

17. Click OK.

18. Repeat steps 12 to 17 for all other buttons that you want to add to the switchboard.

19. Click Close.

20. Click Close.

21. "Switchboard" is added in the Forms section of the Navigation Pane.

Switchboard created using the Switchboard Manager

Editing a Switchboard created using the Switchboard Manager

1. Click the Switchboard Manager command on the Quick Access Toolbar.

2. Select the switchboard that you want to edit.

3. Click Edit….

4. Proceed as described in steps 12 to 20 above.

Alternatively

1. Right click the Switchboard form in the Navigation Pane.

Page 210: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 205

2. Select Design View.

3. Make changes to the form structure and formatting as required.

4. Save and close the form design.

CREATING A SWITCHBOARD IN A DATABASE WITH

OVERLAPPING WINDOWS

Discussion

If the database that you are using was originally created in versions prior to 2007, objects may open in their own separate windows. If the database was created from new in Access 2010 or 2007, tabbed windows are normally used as a default.

Tabbed “documents” as used by default in an Access 2007or 2010 database

Pre-2007/2010 Access database showing objects in their own windows

Page 211: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 206

If you are creating a switchboard in a database where the objects display in separate windows, you may not wish the switchboard to look like a typical form. You should, therefore, set the form properties listed in the following table.

Property Setting

Default View Single Form

Record Selector No

Navigation Buttons No

Auto Center Yes

Scroll Bars Neither

Auto Resize Yes

Min Max Buttons None

Procedure

1. Follow the procedure for creating a switchboard from a blank form as described on page 202.

2. If necessary, click the Property Sheet command on the Design tab under Form Design Tools.

3. In the Property Sheet, click the Format tab.

4. Set properties as described in the table above this procedure.

5. Save the form (suggest naming it Switchboard) and close it.

Switchboard shown in its own window - note unnecessary items.

Tip You can quickly open or close the Property Sheet by pressing F4.

Record selector

Navigation buttons

Min Max buttons

Min Max

Close button

Page 212: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 207

Switchboard shown in its own window with unnecessary items removed

Tip

To change a database from displaying in overlapping windows to tabbed documents and vice versa, click the File tab, click Options

and in the Current Database pane, select the required option under Document Window Options.

You will need to re-open the database for the change to take effect.

OPENING A SWITCHBOARD AUTOMATICALLY

Discussion

Once you have created the switchboard for your database, you may wish for it to show automatically upon opening the database file.

This is achieved either by creating a macro named autoexec that opens the switchboard form (see page 188) or by setting special Access options.

In addition to showing the switchboard, you may also wish to hide the Navigation Pane for that file in order to restrict users to just using the functionality offered by the switchboard. This is also achieved using Access options.

Page 213: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 208

Procedure

1. To automatically show a switchboard form that you have created from scratch (ie. not using the Switchboard Manger) upon opening a database file, select the File tab.

2. Click the Options .

3. Select Current Database in the pane at the left.

4. Click the Display Form drop-down list in the Application Options section.

5. Select the name of the switchboard form.

6. In the Navigation section below, deselect the Display Navigation Pane check box.

7. Click OK. You will have to close and re-open the database for the changes to take effect.

Page 214: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 209

EXERCISE

Using Switchboards

1. Open Train18.

2. Create a blank form and immediately change the view to Design View.

3. Insert the image, WWPLogo, at the right of the form.

4. Add a label to the top of the form with the text Training Database.

5. Format this to taste.

6. Change the Format properties of the form as shown in the following table:

Property Setting

Scroll Bars Neither

Record Selectors No

Navigation Buttons No

Auto Center Yes

Record Selectors No

Min Max Buttons None

7. Close the property sheet.

8. Disable the Control Wizards, if necessary. Add a command button to the upper left corner of the form.

9. Open the property sheet for the command button.

10. On the Event page, set the On Click property to run the Open Payment/Invoice

Forms macro. On the Format page, enter the text Open Forms as the caption.

11. Close the property sheet.

12. Create another command button the form approximately 1.5cm (1/2”) below the Open Forms button. Open the property sheet for the command button.

13. On the Event page, set the On Click property to run the Client Macros.PrintCIReport macro. On the Format page, enter the text Print Report as the caption.

14. Close the property sheet.

15. Enable the Control Wizards. Add another command button to the form approximately 1.5cm (1/2”) below the Print Report button.

16. In the Command Button Wizard, select the Application category and the Quit

Application action. Display text on the button that reads Close Switchboard. Name the button Closes Switchboard.

17. Move/Size the buttons as necessary. Use the screenshot on the following page as a guide to what is required.

18. Close and save the form with the name Main Switchboard.

Page 215: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Lesson 15 – Using Switchboards

WWP Training Page 210

19. Specify in Access Options for the Switchboard to display upon opening the database file (Hint: Current Database pane).

20. Close and reopen this database; notice that the switchboard opens.

21. Test the buttons on the switchboard.

22. Close any open windows, as necessary.

23. Close the database file.

Page 216: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 211

APPENDIX A - CUSTOMISING THE QUICK ACCESS TOOLBAR AND THE RIBBON

In this lesson, you will learn how to:

Customise the Quick Access Toolbar

Customise the Application Ribbon

Page 217: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 212

ADDING COMMANDS TO THE QUICK ACCESS TOOLBAR

Discussion

Users can add any existing command or group on the Ribbon to the Quick Access Toolbar by right-clicking it (or in the case of a group, the group name) and selecting Add to Quick Access Toolbar.

Export to Excel and Relationships command added to the

Quick Access Toolbar together with the Create Queries group

Commands not on the Ribbon can also be added to the Quick Access Toolbar by opening the Customize Quick Access Toolbar dialog box. This allows you to filter out commands from a particular category or tab and add them to the toolbar.

The Customise Quick Access Toolbar dialog box also allows you to remove commands from the Quick Access Toolbar or reset it completely to it default setting. In the case of macro buttons, they can be personalised by changing their image or “HelpTip” (Display name).

Page 218: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 213

The Customize the Quick Access Toolbar dialog box

Procedures

1. Right-click any command or group name.

2. Select Add to Quick Access Toolbar.

3. To remove a command or group, right-click the item on the Quick Access Toolbar and select Remove from Quick Access Toolbar.

Or

4. Click the Customize Quick Access Toolbar drop down arrow at the right of the

Quick Access Toolbar .

5. Select a commonly used command from the list.

Or

1. Click the Customize Quick Access Toolbar drop down arrow at the right of the

Quick Access Toolbar .

2. Click More Commands....

3. Select a category of command or tab in the Choose Commands from: drop down box.

Page 219: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 214

4. Select the required command in the list at the left.

5. Click Add>>.

6. If necessary, click the Move Up or Move Down buttons at the far right of the dialog box to reposition the button in the list.

7. Click OK.

To remove buttons from the Quick Access Toolbar

1. Click the Customize Quick Access Toolbar drop down arrow at the right of the

Quick Access Toolbar .

2. Click More Commands....

3. Select the command that you want to remove in the list at the right.

4. Click Remove.

5. Click OK.

To reset the Quick Access Toolbar

1. Click the Customize Quick Access Toolbar drop down arrow at the right of the

Quick Access Toolbar .

2. Click More Commands....

3. Click the Reset button.

4. Select Reset only Quick Access Toolbar.

5. Click Yes.

6. Click OK.

CUSTOMISING THE APPLICATION RIBBON

Discussion

The Ribbon — the strip across the top of the program window that contains groups of commands — has been a component of most Microsoft Office applications since version 2007. The Ribbon provides a single place for commands and was the primary replacement for the menus and toolbars in earlier versions of Office.

You can personalise the Ribbon in all Office 2010 applications that use it, and get it just the way you want. For example, you can create custom tabs and custom groups to contain your frequently used commands.

Page 220: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 215

The Customize the Ribbon dialog box

You can rename and change the order of the default tabs and groups that are built-into the Ribbon. However, you cannot rename the default commands, change the icons associated with these default commands, or change the order of these commands. The default commands appear in grey text.

To add commands to a group, you must add a custom group to a default tab or to a new, custom tab. To help you identify a custom tab or group and to distinguish from a default tab or group, the custom tabs and groups in the Customize the Ribbon list have (Custom) after the name, but the word (Custom) does not appear in the ribbon.

Remember: You can only add commands to custom groups.

When making changes to the Access Ribbon, you will normally be asked to close and re-open the database to effect the change.

Default tab and group with commands that cannot be changed

Custom group in a default tab that has new commands added. These new commands can be changed

Page 221: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 216

Procedures

Open the Customize Ribbon dialog box

1. Select the File tab.

2. Click Options.

3. Select Customize Ribbon at the left.

Add a custom tab

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, click New Tab.

3. Click Rename....

4. Type a name for the custom tab in the Display name box.

5. Click OK.

6. Click OK.

Rename a default or custom tab

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, select the tab that you want to rename.

3. Click Rename....

4. Type a new name for the tab in the Display name box.

5. Click OK.

6. Click OK.

Hide a default or custom tab

You can hide both custom and default tabs, but you can only remove custom tabs.

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, clear the check box next to the default tab or custom tab that you want to hide.

3. Click OK.

Change the order of default or custom tabs

1. Open the Customize Ribbon dialog box

2. Under the Customize the Ribbon list, click the tab that you want to move.

3. Click the Move Up or Move Down arrow until you have the order you want.

4. To see and save your customizations, click OK.

Remove a custom tab

You can hide both custom and default tabs, but you can only remove custom tabs.

1. Open the Customize Ribbon dialog box

2. Under the Customize the Ribbon list, click the tab that you want to remove.

3. Click Remove.

4. Click OK.

Page 222: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 217

Add a custom group to a tab

You can add a custom group to either a custom tab or a default tab.

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, click the tab that you want to add a group to.

3. Click New Group.

4. Click Rename.

5. Type a name for the group in the Display name box.

6. Click OK.

7. Click OK.

Rename a default or custom group

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, click the tab or group that you want to rename.

3. Click Rename.

4. Type a new name for the group in the Display name box.

5. Click OK.

6. Click OK.

Change the order of the default and custom groups

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, click the group that you want to move.

3. Click the Move Up or Move Down arrow until you have the order you want.

4. Click OK.

Remove a default or custom group

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, click the group that you want to remove.

3. Click Remove.

4. Click OK

Replace a default group with a custom group

You can’t remove a command from a default group, ie. a group built-into Access. However, you can make a custom group with only the commands that you want to replace the default group.

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, click the default tab where you want to add the custom group.

3. Click New Group.

4. Click Rename.

5. Type a name for the new group in the Display name box.

6. Select an icon to represent the new group when the Ribbon is resized.

7. Click OK.

8. In the Choose Commands from list, click Main Tabs.

9. Click the plus sign (+) next to the default tab that contains the group that you want to customize.

Page 223: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 218

10. Click the plus sign (+) next to the default group that you want to customize.

11. Select the command that you want to add to the custom group.

12. Click Add; you don’t have to add all the commands, you can just add the ones that you want.

13. Right-click the default group, and click Remove.

Add commands to a custom group

You can only add commands to a custom group that is under a custom or default tab. You cannot add commands to a default group. Only commands added to custom groups can be renamed.

1. Open the Customize Ribbon dialog box

2. In the Choose commands from list, click the category you want to add commands from, for example, Popular Commands or All Commands.

3. Select the required command in the list.

4. Click Add.

5. Click OK.

NB: You can rename a command and add an icon to represent it by selecting the command, and then opening and completing the Rename dialog box.

Remove a command from a custom group

You can only remove commands from a custom group.

1. Open the Customize Ribbon dialog box

2. Under the Customize the Ribbon list, click the command that you want to remove.

3. Click Remove.

4. Click OK.

Rename a command that you added to a custom group

1. Open the Customize Ribbon dialog box

2. Under the Customize the Ribbon list, click the command that you want to rename.

3. Click Rename.

4. Type a new name in the Display name box and, if required, select a new image for the command.

5. Click OK.

6. Click OK.

Change the order of the commands in custom groups

1. Open the Customize Ribbon dialog box.

Page 224: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 219

2. Under the Customize the Ribbon list, click the command that you want to move.

3. Click the Move Up or Move Down arrow until you have the order you want.

4. Click OK.

Reset the Ribbon

You can choose to reset all tabs on the ribbon or only the selected tabs to their original state. When you reset all tabs on the ribbon, you also reset the Quick Access Toolbar to show only the default commands.

Reset the Ribbon to the default settings

1. Open the Customize Ribbon dialog box.

2. Click Reset ▼.

3. Select Reset all customizations.

4. Click Yes.

5. Click OK.

Reset only the selected tab

You can only reset default tabs to their default settings.

1. Open the Customize Ribbon dialog box.

2. Under the Customize the Ribbon list, select the default tab that you want to reset to the default settings.

3. Click Reset▼.

4. Select Reset only selected Ribbon tab.

5. Click OK.

Export a customized ribbon

You can export your ribbon and Quick Access Toolbar customizations into a file that can be imported and used by a co-worker or on another computer.

1. Open the Customize Ribbon dialog box.

2. In the Customize the Ribbon window, click Import/Export.

3. Click Export all customizations.

4. Navigate to a location to store the file.

5. Click Save.

6. Click OK.

Import a customized ribbon

You can import customization files to replace the current layout of the ribbon and Quick Access Toolbar. By being able to import the customization, you can keep Microsoft Office programs looking the same as your co-workers or from computer to computer.

NB: When you import a ribbon customization file, you lose all prior ribbon and Quick Access Toolbar customizations. If you think that you might want to revert to the customization you currently have, you should export them as a “backup” before importing any new customizations.

1. Open the Customize Ribbon dialog box.

2. In the Customize the Ribbon window, click Import/Export.

3. Click Import customization file.

4. Navigate to where the file is stored (it will have a .exportedUI extension).

5. Select the file.

Page 225: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix A - Customising the Quick Access Toolbar & the Ribbon

WWP Training Page 220

6. Click Open.

7. Click Yes.

8. Click OK.

Page 226: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 221

APPENDIX B - ADVANCED CUSTOMISATION OF THE USER INTERFACE

In this lesson, you will learn how to:

Customise the Ribbon for different Access databases

Customise the Ribbon for use on specific forms or reports

Create a shortcut menu (right-click) for use with specific forms and reports

Page 227: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 222

CUSTOMISING THE RIBBON

Discussion

It was discussed in Appendix A (page 214) how to use to customise the Ribbon by hiding some or all of the default tabs so that users cannot use certain commands or, by creating new, custom tabs that contain only the commands that you want to be available. This creates a new application Ribbon, ie. one that will be used for ALL databases that you open on your computer.

However, as you begin to build more advanced applications with Access, you might decide that you want to customise the Ribbon for each different database that you open or, if you are creating Access databases for other people to use, you may want a special, customised Ribbon to appear when a database is opened on their computers.

This can be achieved by creating a Ribbon using Extensible Markup Language (XML) and attaching it to a database. When that database is opened, the attached Ribbon will display instead of the standard application one. Although some basic knowledge of XML is helpful, it is not necessary. This topic does not cover XML concepts, but does provide you with a basic Ribbon customisation procedure and some example XML that you can modify to suit your needs, and that will add standard Access commands and macros that you have created yourself to the Ribbon.

There are several places that you can store the XML but one of the easiest methods is to store it in a system table in the current database. The process involves creating a system table named USysRibbons, adding your Ribbon XML to it, and then specifying whether the custom Ribbon displays for the database as a whole or for a specific form or report. You can define multiple custom Ribbons — one for the entire application, and additional ribbons for individual forms or reports in the database.

When you create the USysRibbons table, it will not appear in the Navigation Pane as normal tables do. Access hides it because it is regarded as a "system table" and not designed for normal, everyday use. As a result, it has to be unhidden by opening the Navigation Options dialog box and ticking the Show System Objects check box.

The Navigations Options dialog box Navigation Pane showing system objects

Page 228: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 223

Procedure

Preliminary steps

1. Display system tables in the Navigation Pane as follows:

a. Right-click the Navigation Bar at the top of the Navigation Pane.

b. Click Navigation Options… on the shortcut menu.

c. Under Display Options, tick the Show System Objects check box.

d. Click OK. The Access system tables appear in the Navigation Pane.

2. Enable the display of add-in user interface error messages. Error messages are a valuable source of information when creating and troubleshooting Ribbon customisation XML, so it is a good idea to make Access display them. Use the following procedure:

a. Select the File tab.

b. Click Options.

c. Select Client Settings at the left.

d. Scroll down and under General, tick the Show add-in user interface errors check box.

e. Click OK.

f. Close and re-open the database.

Create the USysRibbons system table.

3. Use this procedure to create the USysRibbons system table. Later, you will use this table to store your Ribbon customization XML.

a. Select the Create tab.

b. Click Table Design in the Tables group.

c. Add the following fields to the table. Be sure to type the field names exactly as shown. If you want, you can add more fields to this table, such as a Comments field to describe the purpose of the Ribbon XML.

Field Name Type Field Size

ID AutoNumber Long Integer

RibbonName Text 255

RibbonXml Memo n/a

d. Select the ID field.

e. Select the Design tab.

f. Click Primary Key in the Tools group.

g. Save the new table as USysRibbons and close it.

Page 229: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 224

Add Ribbon customisation XML to the USysRibbons table

For the purposes of this example, suppose that you want to prevent the users of your database from using any of the tools on the Create tab. Furthermore, you want to create a new tab called A Custom Tab with just the Paste command on it, as shown in the following illustration.

The XML in the following procedure creates this configuration.

1. Open the USysRibbons table.

2. Enter a name for the Ribbon (eg. NormalRibbon) in the RibbonName field.

3. Add the following data to the RibbonXML field. You can copy the XML sample from this page and paste it directly into the field. You will need to significantly increase the column width and row high for the record to see all the text.

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<ribbon startFromScratch="false">

<tabs>

<tab idMso="TabCreate" visible="false" />

<tab id="dbCustomTab" label="A Custom Tab" visible="true">

<group id="dbCustomGroup" label="A Custom Group">

<control idMso="Paste" label="Built-in Paste" enabled="true"/>

</group>

</tab>

</tabs>

</ribbon>

</customUI>

4. Save and close the USysRibbons table.

5. Close and then re-open the database.

Notes: The XML above first instructs Access not to "start from scratch" — that is, it specifies that Access should display the default Ribbon tabs. Then, it tells Access to hide just one of the default tabs (the Create tab). Finally, it creates a new Ribbon tab named "A Custom Tab," adds a command group named "A Custom Group" to the tab, and adds the Paste command to the group.

For more information about this example and how to customise it to suit your needs, see the next topic in this lesson on page 227.

Page 230: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 225

USysRibbons table showing XML for two custom ribbons

To apply the custom Ribbon to the entire database

1. Now that the custom Ribbon XML has been stored in a table, do one of the following — depending on whether you want to apply the Ribbon to the entire database or to a specific form or report.

2. Click the File tab.

3. Click Options.

4. Select Current Database at the left.

5. Under Ribbon and Toolbar Options, select the Ribbon Name drop-down list.

6. Select the Ribbon that you want attached to the database.

7. Click OK.

8. Close and re-open the database. The custom Ribbon will be displayed.

Custom Ribbon with the "Create" tab removed and "A Custom Tab" added

Page 231: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 226

To apply the custom Ribbon to a specific form or report only

1. In the Navigation Pane, right-click the form or report that you want to apply the custom Ribbon to, and then select Design or Layout View from the shortcut menu.

2. If the Property Sheet is not already displayed, press F4 to display it.

3. At the top of the Property Sheet, under Selection type, ensure that the object type (Form or Report) is selected in the list.

4. Select the Other tab on the Property Sheet.

5. Click the drop down arrow for the Ribbon Name property.

6. Select the Ribbon that you want to display when you open the form or report.

7. Save the form or report design changes.

8. Close the form or report.

9. Double-click the form or report in the Navigation Pane to reopen it. The Ribbon that you selected is displayed.

Wrap up

After you verify that your custom Ribbon works correctly, you can hide the system tables again as follows:

1. Right-click the top of the Navigation Pane.

2. Select Navigation Options in the shortcut menu.

3. Under Display Options, untick the Show System Objects check box.

4. Click OK.

Restore the default Ribbon

To stop using a custom Ribbon and restore the default Ribbon, use one of the following procedures, depending on whether the custom Ribbon is being used by the entire application or by a specific form or report.

1. Restore the default application-level Ribbon

a. Select the File tab.

b. Click Options.

c. Select Current Database at the left.

d. Under Ribbon and Toolbar Options, delete the contents of the Ribbon Name box.

e. Click OK.

f. Close and then re-open the database. Access displays its default Ribbon tabs. NB: The Ribbon XML remains in the USysRibbons table until you delete it, so if you want to reinstate the custom Ribbon(s), you can do so by setting the Ribbon Name option back to the value it contained previously.

Page 232: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 227

Restore the default Ribbon for a form or report

1. Open the form or report in Design or Layout View.

2. If the Property Sheet is not already displayed, press F4 to display it.

3. At the top of the property sheet, under Selection type, ensure that the object type (Form or Report) is selected in the list.

4. On the Other tab of the property sheet, delete the contents of the Ribbon Name property box.

5. Save, close, and then reopen the form or report. NB: The Ribbon XML remains in the USysRibbons table until you delete it, so if you want to reinstate the custom Ribbon, you can do so by setting the value in the Ribbon Name property back to the value it contained previously.

UNDERSTAND THE XML EXAMPLE

Discussion

Here is the XML example that was used in the previous topic and an illustration of the custom Ribbon it created.

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<ribbon startFromScratch="false">

<tabs>

<tab idMso="TabCreate" visible="false" />

<tab id="dbCustomTab" label="A Custom Tab" visible="true">

<group id="dbCustomGroup" label="A Custom Group">

<control idMso="Paste" label="Built-in Paste" enabled="true"/>

</group>

</tab>

</tabs>

</ribbon>

</customUI>

In this example, the second line of XML sets the startFromScratch attribute to False. Setting the value to False ensures that Access leaves all of the existing tabs intact and adds any new tabs to the right of the existing ones. Setting this attribute to True removes all of the existing tabs and displays only the ones that you create in your XML.

Even if you set the startFromScratch attribute to False, you can still hide individual tabs. This is demonstrated by the fourth line of XML, which hides the built-in Create tab. The remaining lines create a custom tab and a custom group and then add the built-in Paste command to the group by using the following line of XML.

<control idMso="Paste" label="Built-in Paste" enabled="true"/>

Page 233: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 228

Add additional groups or controls to your custom Ribbon.

You can add more groups and controls to your Ribbon by adding similar lines of XML, and substituting different idMso and label values. For example, to create a control that exports the currently selected object to Excel, use the following XML.

<control idMso="ExportExcel" label="Export to Excel" enabled="true"/>

To add the control to the same group as the Paste command, insert the new line of XML immediately before or after the line that creates the Paste command. To create a new group, you can copy, paste, and modify the XML that creates the A Custom Group group above. The following example demonstrates the XML that adds the two controls to the custom group.

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<ribbon startFromScratch="false">

<tabs>

<tab idMso="TabCreate" visible="false" />

<tab id="dbCustomTab" label="A Custom Tab" visible="true">

<group id="dbCustomGroup" label="A Custom Group">

<control idMso="Paste" label="Built-in Paste" enabled="true"/>

</group>

<group id="dbCustomGroup2" label="Another Custom Group">

<control idMso="ImportExcel" label="Import from Excel" enabled="true"/>

<control idMso="ExportExcel" label="Export to Excel" enabled="true"/>

</group>

</tab>

</tabs>

</ribbon>

</customUI>

This XML adds another group to A Custom Tab. As shown in the following illustration, the new group contains two controls — one that initiates an import operation from Excel, and one that initiates an export operation to Excel.

Note: Each group id and tab id value in a custom Ribbon must be unique.

To learn the idMso value of a command

1. Select the File tab.

2. Click Options.

3. Select Customize the Quick Access Toolbar (or Customize Ribbon) at the left.

Page 234: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 229

4. Move the pointer over the command that you want information about. Access displays the control's idMso value in a ScreenTip, in parentheses.

Add a command to run an Access macro

You can add even more flexibility to your custom Ribbon by adding commands that run Access macros. For example, suppose that you created a macro named MyMacro. To add a command to your Ribbon that runs the macro, add the following line to your XML.

<button id="RunMyMacro" label="Run My Macro" onAction="MyMacro"/>

To add the control to the same group as the Paste command in the earlier example, insert the new line of XML immediately before or after the line that creates the Paste command. The following example demonstrates the XML that adds the command.

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<ribbon startFromScratch="false">

<tabs>

<tab idMso="TabCreate" visible="false" />

<tab id="dbCustomTab" label="A Custom Tab" visible="true">

<group id="dbCustomGroup" label="A Custom Group">

<control idMso="Paste" label="Built-in Paste" enabled="true"/>

<button id="RunMyMacro" label="Run My Macro" onAction="MyMacro"/>

</group>

<group id="dbCustomGroup2" label="Another Custom Group">

<control idMso="ImportExcel" label="Import from Excel" enabled="true"/>

<control idMso="ExportExcel" label="Export to Excel" enabled="true"/>

</group>

</tab>

</tabs>

</ribbon>

</customUI>

Page 235: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 230

CREATING A CUSTOM SHORTCUT MENU FOR USE WITH A

FORM OR REPORT

Discussion

You can use Access macros to create custom shortcut menus that appear when you right-click forms, reports, or individual controls. You can also create custom menus that appear on the Ribbon for specific forms or reports.

To create a menu by using macros, you perform three main steps:

Create a macro group that defines the menu commands.

Create another macro that creates the menu itself.

Attach the menu to a form or report.

Procedure

Step 1: Create submacros for each shortcut menu command

1. Select the Create tab.

2. Select Macro in the Macro & Code group.

3. If necessary, click the Show All Actions in the Show/Hide group.

4. For each command that you want on your custom Shortcut Menu:

a. Select Submacro from the Add New Action drop-down box or double click Submacro under Program flow in the Actions Catalog.

b. Name the submacro with the text that you want to display in the shortcut menu (for example, "Print report" or "Save"). NB: To create a keyboard shortcut for the command, type an ampersand (&) before the letter that you want to be the shortcut key in the command name (for example, "&Save"). This letter will be underlined on the menu.

c. In the Add New Action box for the submacro, select the first action you would like to take place when you click the command on the shortcut menu.

d. Add to the action, any necessary Arguments.

e. If there are more actions that you want to take place when you select this command, add them in the subsequent Add New Action box(es).

f. NB: To create a line between two menu commands, type a hyphen (-) in the Macro Name column between the appropriate menu commands.

5. Save and name the macro, for example, ShortcutMenuCommands.

6. The following illustration shows example submacros for a custom shortcut menu.

Page 236: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 231

Step 2: Create a macro that creates the menu

This step might seem redundant, but to create the shortcut menu from the macro group that you created in Step 1, you must create a second macro that contains the AddMenu macro action.

1. Select the Create tab.

2. Select Macro in the Macro & Code group.

3. Click the Add New Action drop down list.

4. Select AddMenu.

5. Under Action Arguments, in the Menu Name box, type a name for the menu (eg. "Form Commands"). This argument is optional but recommended in case you later wish to add the menu to the Ribbon or create submenus.

6. In the Menu Macro Name box, enter the name of the macro that you created in Step 1.

7. Save and name the macro, for example, AddShortcutMenu.

8. The following illustration shows an example menu macro that creates the menu we designed in Step 1.

Step 3: Attach to a form, report or control

Use this procedure if you want the menu to appear when you right-click a specific form, report, or control, as shown in the following illustration:

Page 237: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 232

1. In the Navigation Pane, right-click the form or report where you want the shortcut menu to appear.

2. Select Design or Layout View.

3. On the Design tab, in the Show/Hide group, click Property Sheet (or press F4).

4. Select the control or object to which you want to attach the shortcut menu. If you want the shortcut menu to appear when you right click anywhere on the form, select Form.

5. On the Other tab in the Property Sheet, click in the Shortcut Menu property box.

6. Set it to Yes.

7. Click in the Shortcut Menu Bar property box.

8. Type the name of the macro that you created in Step 2 (in this example, “AddShortcutMenu”).

9. Save and close the form design.

Notes

Custom shortcut menus replace the default shortcut menus for the objects they are attached to. If you want to retain certain Access commands to use on these menus, use the RunCommand action to put the commands into the macro groups for the menus you want them in.

A custom shortcut menu that is attached to a control supersedes any other custom shortcut menus that are defined in the database. A custom shortcut menu that is attached to a form or report supersedes a custom global shortcut menu.

When you specify a menu macro for a form or report or for the database, Access runs this menu macro whenever the form, report, or database is opened. If you make changes to the menu macro or the submacro that defines its commands while the form, report, or database is open, you must close the form, report, or database and re-open it to see the changes.

Page 238: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix B – Advanced Interface Customisation

WWP Training Page 233

To create a submenu, follow Step 1 to create a separate submacro that contains only the submenu commands. Then, follow Step 1 again to define the commands for the higher-level menu. Add the submenu as an item in the higher-level submacro by using the AddMenu action.

The following illustration shows the macro group for a menu that contains a submenu, and then shows the resulting shortcut menu.

You can create multiple levels of submenus by using AddMenu actions in the submacros for each level of menu. Make sure to supply a value for the Menu Name argument for each AddMenu action, otherwise the submenu will appear as a blank line in the higher-level menu.

Macro conditions are supported in the top-level menu macro only. In other words, you can use a condition in a menu macro to determine if a particular menu or shortcut menu will be displayed, but only for the menus on the top level. You can't use conditions to display or hide commands or submenus on the menus. You can also use a condition to hide or show a custom shortcut menu or global shortcut menu.

Optionally, the menu macro that you create in Step 2 can be part of a submenu. For example, if you have several shortcut menus for different objects or controls, you can create a single macro object that contains all of the necessary menu macros. Make sure to create appropriate submenus for each and type a unique name for each macro. In Step 3, use the following notation to refer to the macro: macrogroupname.macroname. eg. AddShortcutMenus.AddMenu2.

Page 239: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 234

APPENDIX C - ADDING MACROS TO TABLE EVENTS (DATA MACROS)

In this lesson you will learn:

How to work with data macros

How to work with named macros

Manage data and names macros

Page 240: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix C – Adding Macros to Table Events

WWP Training Page 235

CREATING DATA AND NAMED MACROS

Discussion

Data macros are a new feature of Access 2010 which enable you to add logic to events that occur in tables, such as adding, updating, or deleting data. You can program a data macro to run immediately after any of these three events, or immediately before a delete or change event.

Data macros are managed from the Table tab on the Ribbon while viewing a table in Datasheet view; they do not appear in the Macros section of the Navigation Pane.

Among other things, you can use data macros to validate and ensure the accuracy of data in a table. There are two main types of data macros—those that are triggered by table events (also called "event-driven" data macros), and those that run in response to being called by name (also known as "named" data macros).

Procedures

Create an event-driven data macro

1. Open the table to which you want to add the data macro.

2. Select the Table tab under Table Tools.

3. In the Before Events group or the After Events group, click the event to which you want to add the macro. The Macro Designer opens.

NB: If an event already has a macro associated with it, its icon appears highlighted on the Ribbon.

4. Access opens the Macro Designer. If a macro was previously created for this event, Access displays the existing macro.

5. Add the action(s) that you want the macro to perform.

6. Save and close the macro.

Create a named data macro

A named or "standalone" data macro is associated with a specific table, but not with a specific event. You can call a named data macros from any other data macro or standard macro.

1. Open the table to which you want to add the data macro.

2. Select the Table tab under Table Tools.

3. Click Named Macro in the Named Macro group.

4. Select Create Named Macro in the menu.

Page 241: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix C – Adding Macros to Table Events

WWP Training Page 236

5. Access opens the Macro Designer, where you can begin adding actions as described in other topics of this lesson.

Parameters

Parameters enable you to pass values into a named data macro so that they can be used in conditional statements or other calculations. They also enable you to pass object references from standard macros into the data macro.

1. At the top of the named macro code sheet, click Create Parameter .

2. In the Name box, type a unique name for the parameter. This is the name that you use to refer to the parameter in expressions.

Optionally, type a description for the parameter in the Description box. We recommend that you enter a description because later, when you use the parameter, the description text you type here is displayed in a tooltip. This helps you remember the purpose of the parameter.

To run a named data macro from another macro, you use the RunDataMacro action. The action provides a box for each parameter that you created, so that you can provide the necessary values.

MANAGING DATA AND NAMED MACROS

Discussion

Data macros do not appear in the Navigation Pane under Macros. You must use the ribbon commands in Table Datasheet view or Table Design view to create, edit, rename, and delete data macros.

Procedure

Edit an event-driven data macro

1. Open the table containing the data macro that you want to edit.

2. Select the Table tab under Table Tools.

3. Click the event for the macro that you want to edit. NB: If an event does not have a macro associated with it, its icon is not highlighted on the menu. The Macro Designer opens.

4. Make changes as necessary.

5. Save and close the macro.

Edit a named data macro

1. Open the table containing the data macro that you want to edit.

2. Select the Table tab under Table Tools.

Page 242: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix C – Adding Macros to Table Events

WWP Training Page 237

3. Click Named Macro in the Named Macros group.

4. Hold the mouse pointer over Edit Named Macro.

5. Select the data macro that you want to edit in the side menu. The Macro Designer opens.

6. Make changes as necessary.

7. Save and close the macro.

Rename a named data macro

1. Open the table containing the data macro that you want to edit.

2. Select the Table tab under Table Tools.

3. Click Named Macro in the Named Macros group.

4. Select Rename/Delete Macro.

5. In the Data Macro Manager dialog box, click Rename next to the data macro that you want to rename.

6. Type a new name for the macro.

7. Press [Enter]

8. Click Close.

Page 243: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix C – Adding Macros to Table Events

WWP Training Page 238

Delete a data macro: use this procedure to delete any named or event-driven data macro.

1. Open the table containing the data macro that you want to edit.

2. Select the Table tab under Table Tools.

3. Click Named Macro in the Named Macros group.

4. Select Rename/Delete Macro.

5. In the Data Macro Manager dialog box, click Delete next to the data macro that you want to remove.

Page 244: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 239

APPENDIX D - USING ACCESS AND THE INTERNET

In this lesson, you will learn how to:

Update a table using email

Import a HTML file

Export to a HTML file

Import from SharePoint

Page 245: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 240

UPDATING DATA VIA EMAIL

Discussion

You can collect or update information though e-mails by using Access with Outlook. Access guides you through creating a data collection form and sending the form in an e-mail message. When your e-mail recipients return the completed forms, you can choose to have the collected data automatically processed and stored in a specified Access database. This method of data collection can save you time and effort that is usually involved in a copy and paste or a manual data entry process. The following are some scenarios where you can use this process to collect data:

Surveys : You can do a survey and compile the results by first creating an Access database with the necessary tables to store the results, and using the wizard to generate a survey form, and then mail them to the survey participants. When participants reply, the survey data is stored automatically in the database.

Status reports : Whether it is the latest inventory level status or the up-to-date information on pending issues, your team can keep you informed by sending you e-mail messages that contain the current information at regular intervals.

Event management : When organizing a conference or training or other events, you can send one or more forms as an e-mail message to gather contact information, travel and hotel preferences, and so on. If you choose to have the replies automatically processed, the participants are able to change their preferences at any time without having to notify you, and you always have access to the latest data for decision making purposes.

Procedure

1. Open the database in which the collected data will be stored.

2. To add the data to a single table, select the table in the Navigation Pane. To populate multiple related tables, select the query that is bound to these tables.

3. Do any one of the following to start the wizard:

a. On the External Data tab, in the Collect Data group, click Create E-mail.

b. Right-click the table or query, and then click Collect and Update Data via E-mail.

NB: If the table does not contain any fields, or only has the AutoNumber, OLE Object, Attachment, or multivalued Lookup field types, Access displays the following message: The selected table or query does not have any fields that

support collecting data using e-mail.

4. If the table contains fields that support data collection, the wizard starts. If the destination table supports both the adding and the updating of data, the wizard guides you through the required steps to collect data through e-mail messages.

There are then a further seven steps to the process.

A. Choose the type of data entry form that you want to send

Select the type of form based on the ease of use for yourself and your recipients. Options are:

a. Select HTML form - An HTML form can be viewed and edited by any user whose e-mail client supports HTML

Page 246: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 241

b. Select Microsoft InfoPath form - You will see this option only If InfoPath is installed on your computer. Select this option only if your recipients all have InfoPath and Outlook installed on their computers. An InfoPath form offers a better data entry and editing environment,

NB: The wizard page that is displayed next depends on whether the destination object supports the updating of data. If the object is a query based on two or more tables, or if it is a table that does not have a primary key field or does not contain any records, the wizard assumes that you want to add new records, and prompts you to select the form fields. In all other cases, the wizard prompts you to specify whether you want to add or update data before asking you to select the form fields.

B. Choose whether to collect new data or update existing data

Specify what you want to do with the data. The type of form that you are using affects the number of new records that a recipient can send to you in a single reply. When updating data, the number of records that must be updated by a recipient identifies the number of pre-completed forms that will be included in a message.

NB: To add new records, type the e-mail addresses in the address box of the e-mail message when the message is created. To update existing data, the e-mail addresses of the recipients must be stored as a field in the underlying table or query, or in a related table.

C. Specify the data you want collected

When choosing the fields to include in your form, it is not necessary to include every field that exists in the underlying table or query in the form. However, the following conditions must be met:

a. Required fields: Fields marked with an asterisk (*) symbol, are required fields. If you are collecting new records, the wizard will automatically include all fields whose Required property is set to Yes. If any record's required fields are blank, Access fails to add the record to the table.

b. Unsupported field types: You will not be able to include certain field types in the form such as, AutoNumber, Attachment, OLE Object, or multivalued lookup fields.

c. Primary key field: The user will be able to type a value in the field when adding records however; the reply will not be processed if the specified value is already in use.

d. Note For each included field, under Field Properties, specify a label and click Read-only if you don't want the user to change the data in that field.

D. Specify automatic or manual data processing

You can select an automatic or manual processing of replies. Automatic processing means that when you get the replies, Outlook and Access work together to export the data to the destination tables in your database. Automatic processing can save you time and effort. Manual processing only means that you start the export operation to transfer the data from a specified folder in Outlook, to the destination table in Access.

Replies are successfully exported to the destination table as long as the following conditions are met at the time the replies reach your mailbox:

a. Outlook must already be running on your computer. If Outlook is not running, processing starts the next time that you start Outlook.

Page 247: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 242

b. Access must not be password-protected, and should not be open in Exclusive mode. The name or location of the database must not have changed since you sent the e-mail message.

c. The names of the tables and queries, and the properties of the fields included in the form, must not have changed since you sent the e-mail message.

d. You must have the required permissions to add or update the contents of the underlying tables and query.

NB: If automatic processing fails, try fixing any issues, and then manually export the replies that failed. Any replies that reach your inbox after you resolve the issues continue to be processed automatically.

Set properties to control the automatic processing of replies

To specify a different Outlook folder where replies are stored, on the Specify how you

want to process the replies page of the wizard, click the folder name. In the Select

Folder dialog box, either select a different folder, or click New to create a new folder.

If you click Set properties to control the automatic processing of replies to change or fine tune import settings, see the following table for information on the available options:

Option Result

Discard replies from those to whom you did not send the message

Select this check box if you want only those replies that were sent by the original recipients of your message to be automatically processed. Replies from other people are stored in the destination folder, but are not automatically processed.

Accept multiple replies from each recipient

Select this check box if you want only the first reply from each recipient to be processed automatically. The second and subsequent replies are stored in the destination folder, but are not automatically processed.

Note This setting only controls the number of replies, and not the number of records within a single reply, that are processed. In other words, if you send an InfoPath form, a user is able to send you multiple records in a single reply, and Access automatically processes all of the records in the reply, even if this check box is not selected.

Only allow updates to existing data

When recipients use an InfoPath form to update data, they can send new records in addition to updates to existing records. Select this check box to process only the updates to existing records.

Number of replies to be processed

Type the total number of replies (from all recipients) that you want automatically processed. If you want all replies to be automatically processed, enter a large value, such as 5000, in the text box. Replies that are received after the specified value is reached are stored in the destination folder, but are not automatically processed.

Date and time to stop Specify when automatic processing of replies should stop for this e-mail message. Replies received after this date and time are stored in the destination folder, but are

Page 248: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 243

not automatically processed.

NB: To change these options at a later date, on the External Data tab, in the Collect

Data group, click Manage Replies. In the Manage Data Collection Messages dialog box, select the message for which you want to change the settings, and then click Message Options. The changes you make in the dialog box affect all subsequent replies that you receive for that message.

Manually processing replies

To control when and which replies are processed, do not select the Automatic process option. The replies will be stored in a specified folder in Outlook until you select and right-click each reply in the folder, and then click Export data to Microsoft Access in the shortcut menu.

In some instances, you might also have to manually process the replies that failed to be processed automatically.

Remember the following before exporting data:

a. The Access database should not be open in exclusive mode, and the name or location of the database must not have changed since you sent the e-mail message.

b. The names of the tables and queries, and the properties of the fields included in the form, must not have changed since you sent the e-mail message.

c. You must have the required permissions to add or update the contents of the underlying tables and query.

E. Select how you want to specify e-mail addresses of the recipients

If you are collecting new information only, you can specify the e-mail addresses in two ways:

a. Type the e-mail addresses individually in the Outlook e-mail message, or select the addresses from an address book.

b. Use the e-mail address field in the table or query of the current Access database.

NB: When collecting data to update existing records, you do not see this dialog box, because the recipients' e-mail addresses must first be available as a field in the database.

Entering the e-mail addresses directly in Outlook

If you are specifying your recipients in Outlook, you can preview and customize the message before sending it. In the e-mail message body includes a brief introduction and a form. It is recommended that you do not make any changes to the form. Changes to the form structure might result in the reply not being processed.

Using the e-mail addresses stored in a field in the database

The option to select An Associated table refers to tables that are related. To view or edit table relationships in your database, on the Database Tools. tab, in the Relationships group, click Relationships

F. Review and specify the list of recipients

The final major step involves previewing and customizing the e-mail message, fine tuning your recipient list, and then sending your data collection message.

G. Create and send the e-mail message

When the wizard informs you that you can now create the e-mail message, and shows you how to view e-mail status by using the Manage Replies command, some warning messages might appear. The following table describes each warning and the action you can take to resolve it:

Page 249: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 244

Warning message Description Solution

Some records do not contain a valid address in the specified e-mail address field. No data will be returned for these rows.

The e-mail address field that you selected contains null values.

If you want to collect data for every record, exit the wizard and replace the null values with e-mail addresses. Then start the wizard again.

You currently have an exclusive lock on the database; automatic processing will fail until the lock is released.

You have the database currently open in exclusive mode.

If you chose to have the replies automatically processed, processing fails because Access cannot add to or update a database that has an exclusive lock on it. Close and reopen the database in non-exclusive mode immediately after sending the message

These e-mail messages might contain data that is of a confidential or sensitive nature.

You are collecting data to update existing records, and the form that you are about to send will be pre-completed with existing data.

If some form fields include sensitive data, go back to the wizard step where you selected the fields and remove the fields that contain sensitive data from the form

After you preview and customise the message, you can filter the e-mail address field and select your recipients. Choose the e-mail addresses that you want to use by selecting the corresponding check boxes. If you see a dialog box listing invalid e-mail addresses, make a note of the addresses in the list and click Exit. Verify the invalid addresses, make any necessary correction, and then try resending the message.

EXPORTING DATABASE OBJECTS TO HTML

Discussion

In Access 2010, you can save a table, query, form, or report, as a Web page using the Export HTML document command. When you save a page in HTML, it displays only the data at the time the file was created. If the data changes, then the data must be exported again in order to update the Web pages.

Procedure

1. Select in the Navigation Pane, the Table, Query, Form, or Report you wish to export.

2. Click the External Data tab.

3. In the Export group, click the More button.

Page 250: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 245

4. Click HTML document.

5. In the Export - HTML Document dialog box, use the Browse… button to locate and specify the file destination.

6. Specify other export options you want.

7. Click OK.

8. If required, specify the HTML output options required. This dialog box will only appear if you have selected Export data with formatting and layout in step 6 above.

9. Click OK.

10. Choose whether or not to save the export steps and click the Close button

Page 251: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 246

Table displaying in Internet Explorer as a HTML file

IMPORTING OR LINKING TO A HTML FILE

Discussion

You can import HTML files as or into Access tables. Access uses the Import HTML Wizard for you to specify how you intend to import the data into your database.

Procedure

1. Open the database you wish to import to.

2. Click the External Data tab.

3. In the Import group, click the More button.

4. Select HTML Document.

Page 252: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 247

5. Specify the name and location of the file.

6. Click OK.

7. Click the option(s) you require for importing the data, ie:

a. Import the source data into a new table in the current database

b. Append a copy of the records to an existing table

c. Link to the data source by creating a linked table.

8. Click OK.

9. Use the Import HTML Wizard pages to specify how you want to import the data.

10. In the final step of the Wizard, name the new table and click Finish.

11. If required, click to save the Import steps.

12. Click the Close button.

13. The HTML file is displayed as a table in the Navigation Pane.

Page 253: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 248

IMPORTING FROM SHAREPOINT

Discussion

If you have access to a Microsoft Office SharePoint Services site, you can import from, export, or move to, a SharePoint list.

A SharePoint Services site is a server application using Web site templates to create, share, and organize, data. To use a SharePoint Services site, you may need access privileges for which you must see your network administrator.

The SharePoint Wizard will guide you through the process of importing, linking, exporting, and moving data, to and from SharePoint.

Page 254: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix D – Access and the Internet

WWP Training Page 249

Since the SharePoint Server is a Web based system, everyone with permission can enter with a simple Web browser.

The Server allows you to create several different types of sites using templates. A Team Site is a template for teams to create, share, and organise information. A Document Workspace is a template for users to post information. A Wiki Site is a template where users can add, edit, and link information.

Procedure

1. To create a table using a SharePoint List, first click the Create tab.

2. In the Tables group, click the SharePoint Lists button.

3. Click the SharePoint list template you want.

4. Enter a SharePoint site address or select an existing one.

5. Enter a name and description.

6. To open the list, place a check in the Open the list when finished check box.

7. Click OK.

Page 255: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 250

APPENDIX E – ADVANCED ACCESS SECURITY

In this lesson, you will learn how to:

Use digital certificates

Create digital certificates

Use the Trust Center

Lock a database

Lock database records

Page 256: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 251

CREATING A DIGITAL SIGNATURE

Discussion

You can show that you believe a database is safe and that its content can be trusted by adding a digital signature to the database. This helps people who use the database decide whether to trust it and its content.

Before you can add a digital signature you need to create a digital ID, or digital certificate, which provides an electronic way to prove your identity. To assure a digital signature is authentic, it must have a valid certificate issued by a reputable certification authority and the signing person must be from a trusted publisher such as a trusted Microsoft partner. If you do not need a verified digital certificate you can create one of your own. Such a certificate would be known as a self-signed certificate. This topic explains how to create your own security certificate.

Procedure

1. To create a self-signed certificate, click the Windows Start button.

2. Point to All Programs.

3. Click Microsoft Office.

4. Click Microsoft Office Tools.

5. Click Digital Certificate for VBA Projects.

6. Enter a name.

7. Click OK.

8. In the Self Cert Success box, click OK.

Page 257: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 252

DIGITALLY SIGNING AND PACKAGING A DATABASE

Discussion

Once you have created a digital signature, you can package the database file, apply a digital signature to the package, and then distribute it to other users, all by using a simple command in the File tab.

Icon for signed and packaged Access Database

This process produces an Access Deployment (.accdc) file from which other users can extract the database from the package and work directly in it (not in the package file).

Important notes:

Packaging a database and signing the package is a way to convey trust. When you package and sign a database, your digital signature confirms that the database has not been altered after you created the package.

After the database is extracted from the package, there is no longer a connection between the signed package and the extracted database.

You can use the Package and Sign tool only with databases saved in an Office Access 2007 or 2010 file format. Access also provides tools to sign and distribute databases that were created in an earlier file format. You must use the digital signature tool that is appropriate for the database file format that you are using.

You can add only one database to a package.

The process digitally signs a package that contains your entire database, not just macros or modules.

The process compresses the package file to help reduce download times.

You can extract databases from package files that are located on SharePoint servers.

Procedure

To create a signed package

1. Open the database you want to sign and package.

2. Select the File tab.

3. Click Save & Publish .

4. Click Save Database As .

Page 258: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 253

5. Under Advanced, click Package and Sign .

6. Click the Save As button .

7. Select the digital certificate you want to use.

8. Click OK. The Create Microsoft Access Signed Package dialog box opens.

9. Specify a location for the database package.

10. Enter a name for the database package.

11. Click the Create button.

To extract and use a signed database

1. Click the File tab.

2. Click Open.

3. In the Files of type: list, select Microsoft Office Access Signed Packages.

Page 259: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 254

4. Locate and select the file you want.

5. Click Open.

6. Choose your preferred option in the Microsoft Access Security Message.

7. If you have chosen to trust or open the package, the Extract Database To dialog box opens.

Page 260: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 255

8. Select a location for the database.

9. Enter a name for the database.

10. Click OK.

USING THE TRUST CENTER

Discussion

The Trust Center security system sets strict criteria on database components. The Trust Center is used to set specific security options and to create, or change, trusted locations.

Page 261: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 256

Procedure

1. To view the Trust Center, click the File tab.

2. Click Options.

3. In the left pane, click Trust Center.

4. At the right, click the Trust Center Settings… button. The following list of options appears (some options may vary):

a. Trusted Publishers Build a list of publishers of code projects you trust.

b. Trusted Locations Designate folders on your computer in which to place files you trust from reliable sources. Files in a trusted location folder do not go through File Validation.

c. Trusted Documents Manage how Office programs interact with active content.

d. Add-ins Select if add-ins require digital signatures, or if add-ins are disabled.

e. ActiveX Settings Manage security prompts for ActiveX controls in Office programs.

f. Macro Settings Enable or disable macros in Office programs.

g. Message Bar Show or hide the Message Bar.

h. File Block Settings Determine if previous versions of Office program files will open.

i. Privacy Options Make selections that determine your level of privacy with Office programs.

5. Click the area for which you want to make changes.

Important: Changing Trust Center settings can greatly reduce or increase the security of your computer, its data, data on your organisation's network, and other computers

on that network. We advise that you seek advice from your IT Department before making Trust Center settings changes.

Page 262: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 257

LOCKING A DATABASE

Discussion

In the Save & Publish pane of the File tab, is the Make ACCDE command. This allows you to lock a file and prevent users from viewing or modifying any VBA code, and from making changes to report or form design.

Icon for ACDDE file

Using the Make ACCDE command changes the file extension from .accdb to .accde and, if the database contains any VBA code, only the compiled code is included in the new file.

When a .accde file is opened, Access creates and opens a temporary locking file with the extension .ladddb to prevent any conflicts. When the file is closed, the temporary file is automatically deleted.

Procedure

1. Open the file you want to lock.

2. Select the File tab.

3. Click Save & Publish .

4. Click Save Database As .

5. Click Make ACCDE .

6. Click the Save As button .

7. In the Save As dialog box, specify a location and a name for the file.

Page 263: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Appendix E – Advanced Access Security

WWP Training Page 258

8. Click the Save button.

LOCKING DATABASE RECORDS

Discussion

In a multi-user environment, more than one user could attempt to edit the same record at the same time. This can be prevented by using record locking, thus ensuring that only one user at any one time can edit data.

You can also prevent conflicts by opening the database in exclusive mode which prevents any other user(s) from accessing the database while you are using it. This is useful for database owners to be able to make changes to the database file.

Procedure

1. Open the required database.

2. Click the File tab.

3. Click the Options button.

4. Click Client Settings in the left pane.

5. In the right pane, scroll down to the Advanced section.

6. Under Default open mode, select the Shared or Exclusive option.

7. Under Default record locking, select the desired option:

8. Click the Open databases by using record-level locking check box.

9. Click OK.

Page 264: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

WWP Training Page 259

INDEX

A

Access Options customising the Quick Access Toolbar ................ 212 customising the Ribbon ....................................... 214

ACDDE file format saving as .............................................................. 257

ActiveX controls adding to a form .................................................... 91

AutCalc in PivotTables & PivotCharts ................................. 68

AutoExec macro ....................................................... 193

B

Backup ....................................................................... 29

C

Calculated controls creating.................................................................. 98

Cascade options in relationships ...................................................... 49

Charts changing the type ................................................ 117 creating in forms and reports .............................. 114 formatting ........................................................... 118

Combo boxes creating.................................................................. 82

Command buttons adding to a form ........................................ 75, 78, 80 adding to switchboard ......................................... 201 creating for macros ............................................. 174

Compacting and repairing ......................................... 29 Control Wizards ................................................... 75, 78

using in forms ........................................................ 75 Controls

ActiveX ................................................................... 91 adding a combo box .............................................. 82 adding a command button .............................. 78, 81 adding a list box to a form ..................................... 85 adding an option group ......................................... 86 adding logic ........................................................... 89 addinga command button .................................... 75 creating calculated ................................................ 98 using the Combo Box tool ..................................... 82

Conversion Access versions ...................................................... 26

Crosstab queries creating.................................................................. 36

Customisation adding macro buttons to a Ribbon ...................... 229 adding XML Ribbon code ..................................... 224 applying a custom Ribbon to a form or report .... 226 applying a custom Ribbon to the database ......... 225 creating shortcut menus ..................................... 230 custom Ribbons ................................................... 223

Extensible Markup Language (XML) .................... 222 restoring default Ribbon to a database ............... 226 Ribbon ......................................................... 214, 222 the Quick Access Toolbar .................................... 212 the Quick Access Toolbar .................................... 164 USysRibbons table ............................................... 223

D

Data exporting ............................................................... 21 importing ............................................................... 12 linking to a table .................................................... 12 the Linked Table Manager ..................................... 21 updating using Outlook ....................................... 240

Data formats .............................................................. 22 Data macros

adding to table events ......................................... 235 managing and editing .......................................... 236

Database Documenter ............................................................. 8 using name autocorrect......................................... 30

Database objects exporting ............................................................... 21 importing ............................................................... 12

Databases backing up ............................................................. 29 compacting ............................................................ 29

Date and Time Picker inserting ActiveX control ....................................... 91

Design View forms ............................................................... 57, 75 reports ................................................................... 97

Digital signature creating ................................................................ 251

Documenter ................................................................. 8

E

Email updating tables using Outlook ............................. 240

Errors handling in macros .............................................. 188

Events examples ...................................................... 170, 171 in tables ............................................................... 235 working with ........................................ 170, 173, 176

Excel exporting from Access ........................................... 19 importing to Access ............................................... 15

Exporting data ........................................................................ 21 data to Excel .......................................................... 19 SharePoint ........................................................... 248

Exporting data as HTML ............................................................... 244

Expression Builder

Page 265: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Index

WWP Training Page 260

using in macros .................................................... 153 using with macros ............................................... 180

Extensible Markup Language (XML) ........................ 222 adding a command to run a macro ..................... 229 creating a USysRibbons table .............................. 223 Ribbon customisation .................................. 224, 227

F

Fields referring to from one form to another................ 140 referring to from one report to another ............. 140 Yes/No ................................................................... 90

Files Converting ............................................................. 26

Find Duplicates Query Wizard using ...................................................................... 37

Find Unmatched Query Wizard using ...................................................................... 38

Footer adding to a report ................................................. 97

Form Design creating custom shortcut menus ......................... 230 working with subforms ........................................ 122

Form Footer ............................................................... 58 Formatting

PivotTables & PivotCharts ..................................... 71 Forms

adding charts ....................................................... 114 adding command buttons ......................... 75, 78, 81 adding logic controls ............................................. 90 assigning macros to ..................................... 173, 176 assigning macros to objects ........................ 170, 174 creating a combo box ............................................ 82 creating a list box .................................................. 85 creating a PivotTable or PivotChart view .............. 63 creating an option group ....................................... 86 creating from blank ............................................... 61 finding records ...................................................... 78 headers & footers .................................................. 58 navigating .............................................................. 81 sections ................................................................. 57 setting the tab order automatically....................... 59 using Control Wizards ........................................... 75 using in Design View .............................................. 57

G

Group footers creating................................................................ 104 creating a summary calculation .......................... 104

Group headers creating................................................................ 104 creating a summary calculation .......................... 104

Grouping report data .......................................................... 101

Groups creating in macros ............................................... 191

H

Header

adding to a report .................................................. 97 HTML

exporting as ......................................................... 244 importing and linking ........................................... 246

I

IF statements adding to macros ......................................... 178, 182 using Else ............................................................. 182 using ElseIf ........................................................... 183

Importing as HTML ............................................................... 246 data from Excel ...................................................... 15 objects from another database ............................. 12 SharePoint ........................................................... 248 the Linked Table Manager ..................................... 21

Indexes creating a multiple field ....................................... 148 creating a multiple field primary key ................... 149 creating a single field ........................................... 147 deleting ................................................................ 149 viewing ................................................................ 146

J

Joins in queries ........................................................... 34

L

Linked Table Manager ................................................ 21 Linking data

as HTML ............................................................... 246 List boxes

creating .................................................................. 85 Locking

create ACDDE file ................................................. 257 database records ................................................. 258

M

Macro Designer ........................................ 153, 158, 161 working with ........................................................ 155

Macro examples automatically filling in fields ................................ 195 ensuring correct data entry ................................. 194

Macros adding a condition ....................................... 178, 182 assigning to a command button .......................... 174 assigning to events ...................................... 170, 173 creating ................................................................ 154 creating a Switchboard ........................................ 201 creating Autoexec ................................................ 193 creating code groups ........................................... 191 creating directly from a form or report ............... 177 creating submacros ............................................. 186 editing existing .................................................... 161 handling errors .................................................... 188 referring submacros ............................................ 187 running ................................................................ 160 running using the Quick Access Toolbar .............. 164 running using the Tools menu ............................. 164 saving ................................................................... 158

Page 266: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Index

WWP Training Page 261

using single step mode for testing ...................... 158 working with ........................................................ 153 working with the message box ............................ 162

Margins changing in reports .............................................. 107

Message Box using in macros .................................................... 162

Microsoft Graph changing the chart type....................................... 117 formatting chart objects ...................................... 118

N

Name AutoCorrect using ...................................................................... 30

Named macros in tables ............................................................... 235 managing and editing .......................................... 236

O

Option group adding to a form .................................................... 86

Outlook using to update Access data ................................ 240

P

Page breaks inserting ............................................................... 105

Page Footer ................................................................ 97 in forms ................................................................. 58

Page Header ............................................................... 97 in forms ................................................................. 58

Password Protection .................................................. 27 Performance Analyzer ................................................. 7 PivotChart

creating a view ................................................ 63, 64 PivotTable

creating a view ...................................................... 63 PivotTable & PivotChart

AutoCalc ................................................................ 68 filtering field items ................................................ 68 hiding and unhiding items ..................................... 70 properties .............................................................. 70 refreshing .............................................................. 65

Preferences customising the Ribbon ....................... 216, 217, 218

Primary key creating a multiple field ...................................... 149

Properties using ............................................................ 173, 175 using with macros ....................................... 170, 176

Q

Queries Crosstab ................................................................. 36 Find Duplicates ...................................................... 37 find unmatched ..................................................... 39 join types ............................................................... 34

Quick Access Toolbar adding macros buttons to ................................... 164

Quick Access Toolbar customising .......................................................... 212

Quick Access Toolbar resetting .............................................................. 214

R

Referential integrity setting .................................................................... 48

Relationships cascade options ..................................................... 49 creating between tables .................................. 43, 46 deleting .................................................................. 53 primary and foreign tables .................................... 44 setting referential integrity ................................... 48 subdatasheets ....................................................... 51 types ...................................................................... 44 window .................................................................. 46

Report design working with subreports ..................................... 122

Reports adding charts ....................................................... 114 adding headers and footers ................................... 97 assigning macros to ..................................... 173, 176 changing margins ................................................. 107 creating a calculated control ................................. 98 creating from blank ............................................. 108 creating without a wizard .................................... 108 grouping data ...................................................... 101 inserting a page break ......................................... 105 sections .................................................................. 97 sorting .................................................................. 100 summary calculations .......................................... 104

Ribbon advanced customisation ...................................... 222 customising .................................. 214, 216, 217, 218 exporting and importing customisations............. 219 Extensible Markup Language (XML) .................... 222 resetting customisations ..................................... 219

S

Security creating a digital signature .................................. 251 Encryption ............................................................. 27 locking a database ............................................... 257 locking records .................................................... 258 signing and packaging a database ....................... 252 Trust Center ......................................................... 255

Shortcut menus customising .......................................................... 230

Signing and packaging a database ........................... 252 Sorting

reports ................................................................. 100 Startup

opening a Switchboard ........................................ 207 Subdatasheets

viewing .................................................................. 51 Subforms

displaying a total ................................................. 140 editing the layout ................................................ 136

Page 267: VERSION 2010 ADVANCED - WWP 2010 Advanced Course Book.pdf · Microsoft Access 2010 – Advanced Lesson 1 – Normalisation WWP Training Page 3 Fifth Normal Form A Database is in the

Microsoft Access 2010 – Advanced Index

WWP Training Page 262

working with ........................................................ 122 Submacros

creating................................................................ 186 referring to .......................................................... 187

Subreports displaying a total ................................................. 140 editing the layout ................................................ 136 working with ........................................................ 122

Switchboard Manager ............................................. 203 Switchboards

adding a command button .................................. 201 creating................................................................ 201 creating in separate window ............................... 205 opening ................................................................ 201 opening on database launch ............................... 207 pre-2007 versions ................................................ 206 the Switchboard Manager ................................... 202 using .................................................................... 201

T

Tab order setting automatically in forms ............................... 59

Table Analyzer Wizard ................................................. 5 Tables

analyzing .............................................................. 5, 7

assigning macros to events.................................. 235 deleting relationships ............................................ 53 importing from another Access database ............. 12 indexing fields ...................................................... 146 joining .............................................................. 43, 46 linking .................................................................... 12 linking data ............................................................ 12 splitting .................................................................... 5 viewing subdatasheets .......................................... 51

The Chart Wizard ..................................................... 114 The Macro Builder ................................................... 186 Tools

Backing up a database ........................................... 29 compacting ............................................................ 29 Database Documenter ............................................. 8 Encryption ............................................................. 27 Performance Analyzer ............................................. 7

Trust Center settings ................................................................ 256

W

Windows viewing objects in overlapping ............................ 205

Word Options customising the Ribbon ....................... 216, 217, 218