153
WWP Learning and Development Ltd Page i ACCESS 2007 ADVANCED

Access 2007: Advanced · 2020-03-13 · Access 7.0 (95), Access V2/V1), Access 2007 holds the file in compatibility mode where it disables features which cannot be displayed or converted

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

WWP Learning and Development Ltd Page i

ACCESS 2007 ADVANCED

Contents

Page ii WWP Learning and Development LTd

CONCEPTS OF NORMALISATION ............................................................................................................1

INTRODUCTION ...............................................................................................................................................1

FIRST NORMAL FORM .....................................................................................................................................1

SECOND NORMAL FORM .................................................................................................................................1

THIRD NORMAL FORM ....................................................................................................................................1

FOURTH NORMAL FORM .................................................................................................................................2

FIFTH NORMAL FORM .....................................................................................................................................2

JUNCTION TABLES ..........................................................................................................................................2

ANALYSING TABLES ...................................................................................................................................3

INTRODUCTION ...............................................................................................................................................3

USING THE TABLE ANALYSER WIZARD ..........................................................................................................3

USING THE PERFORMANCE ANALYZER ..........................................................................................................5

DOCUMENTING A DATABASE .........................................................................................................................6

Exercise - Analysing Tables .......................................................................................................................7

TRANSFERING DATA ...................................................................................................................................9

INTRODUCTION ...............................................................................................................................................9

LINKING DATA TO AN ACCESS TABLE ......................................................................................................... 10

USING THE LINKED TABLE MANAGER ......................................................................................................... 11

EXPORTING DATA ......................................................................................................................................... 11

CONVERTING FILES....................................................................................................................................... 14

Exercise – Transferring Data .................................................................................................................. 15

DATABASE TOOLS ..................................................................................................................................... 17

INTRODUCTION ............................................................................................................................................. 17

ADDING SECURITY ENCRYPTION TO A DATABASE (PASSWORD PROTECTING)............................................. 17

COMPACTING AND REPAIRING A DATABASE ............................................................................................... 18

USING NAME AUTOCORRECT ........................................................................................................................ 19

BACKING UP A DATABASE ........................................................................................................................... 19

Exercise – Database Tools ...................................................................................................................... 21

DESIGNING ADVANCED QUERIES ........................................................................................................ 23

INTRODUCTION ............................................................................................................................................. 23

JOINING TABLES IN QUERIES ........................................................................................................................ 23

CROSS PRODUCTS ......................................................................................................................................... 24

CREATING REVERSE OUTER JOINS ................................................................................................................ 24

USING THE CROSSTAB QUERY WIZARD ....................................................................................................... 25

USING THE FIND DUPLICATES QUERY WIZARD ............................................................................................ 26

USING THE UNMATCHED QUERY WIZARD ................................................................................................... 28

Exercise - Designing Advanced Queries .................................................................................................. 29

CREATING RELATIONSHIPS ................................................................................................................... 31

INTRODUCTION ............................................................................................................................................. 31

CREATING A RELATIONSHIP BETWEEN TABLES ............................................................................................ 32

SETTING REFERENTIAL INTEGRITY ............................................................................................................... 33

VIEWING SUBDATASHEETS ........................................................................................................................... 34

DELETING A JOIN LINE ................................................................................................................................. 35

PRINTING RELATIONSHIPS ............................................................................................................................ 35

Exercise - Creating Relationships ........................................................................................................... 37

FORM DESIGN TOOLS AND METHODS ................................................................................................ 38

INTRODUCTION ............................................................................................................................................. 38

SETTING THE TAB ORDER AUTOMATICALLY ................................................................................................ 39

SETTING THE TAB ORDER MANUALLY ......................................................................................................... 39

ADDING A FORM HEADER AND FOOTER ...................................................................................................... 40

CREATING A FORM WITHOUT USING THE WIZARD ...................................................................................... 41

CREATING A PIVOTTABLE OR PIVOTCHART VIEW ........................................................................................ 41

Exercise – Form Design Tools and Methods ........................................................................................... 45

WWP Learning and Development Ltd Page iii

AUTOMATING FORMS WITH CONTROL WIZARDS ......................................................................... 47

INTRODUCTION ............................................................................................................................................. 47

ACTIVATING THE CONTROL WIZARDS .......................................................................................................... 47

CREATING COMMAND BUTTONS TO CARRY OUT FORM ACTIONS ................................................................ 48

CREATING COMMAND BUTTONS TO CARRY OUT REPORT ACTIONS ............................................................. 49

CREATING COMMAND BUTTONS TO CARRY OUT RECORD NAVIGATION/OPERATION .................................. 50

CREATING A COMBO BOX ............................................................................................................................ 50

CREATING A LIST BOX ................................................................................................................................. 51

CREATING AN OPTION GROUP ...................................................................................................................... 52

ADDING A LOGIC CONTROL ......................................................................................................................... 54

ACTIVEX CONTROLS .................................................................................................................................... 55

ADDING AN ACTIVEX CONTROL ................................................................................................................ 56

ATTACHING AN ACTIVEX CONTROL .......................................................................................................... 56

Exercise - Automated Controls on Forms ................................................................................................ 58

ADVANCED REPORT DESIGN ................................................................................................................. 61

INTRODUCTION ............................................................................................................................................. 61

CREATING A CALCULATED CONTROL .......................................................................................................... 62

GROUPING DATA IN A REPORT ..................................................................................................................... 63

CREATING GROUP HEADERS AND FOOTERS ................................................................................................. 64

CREATING A RUNNING SUMMARY................................................................................................................ 66

INSERTING A DATE/TIME CONTROL ............................................................................................................. 67

INSERTING A PAGE BREAK ........................................................................................................................... 67

CHANGING THE REPORT MARGINS ............................................................................................................... 68

CREATING A REPORT WITHOUT USING A WIZARD ...................................................................................... 69

Exercise - Using Advanced Report Design .............................................................................................. 70

USING CHARTS ............................................................................................................................................ 73

INTRODUCTION ............................................................................................................................................. 73

CHANGING THE CHART TYPE ....................................................................................................................... 75

FORMATTING CHART OBJECTS ..................................................................................................................... 75

FORMATTING THE CHART TITLE................................................................................................................... 77

ADDING DATA LABELS TO A CHART ............................................................................................................ 78

Exercise - Using Charts ........................................................................................................................... 79

USING SUBFORMS/SUBREPORTS ........................................................................................................... 81

INTRODUCTION ............................................................................................................................................. 81

EDITING THE LAYOUT OF A SUBFORM ......................................................................................................... 83

DISPLAYING A SUBFORM IN DATASHEET VIEW ............................................................................................ 83

DISPLAYING A SUBFORM TOTAL .................................................................................................................. 84

Exercise - Using Subforms/Subreports .................................................................................................... 86

WORKING WITH INDEXES ...................................................................................................................... 87

INTRODUCTION ............................................................................................................................................. 87

CREATING A SINGLE FIELD INDEX ............................................................................................................... 88

CREATING A MULTIPLE FIELD INDEX ........................................................................................................... 89

DELETING AN INDEX .................................................................................................................................... 90

CREATING A MULTIPLE FIELD PRIMARY KEY .............................................................................................. 91

Exercise - Working with Indexes ............................................................................................................. 92

WORKING WITH MACROS ...................................................................................................................... 93

INTRODUCTION ............................................................................................................................................. 93

CREATING A MACRO .................................................................................................................................... 94

ASSIGNING AN ARGUMENT TO AN ACTION.................................................................................................. 95

SAVING A MACRO ........................................................................................................................................ 95

USING SINGLE STEP MODE FOR TESTING A MACRO .................................................................................... 96

RUNNING A MACRO ..................................................................................................................................... 97

EDITING AN EXISTING MACRO ..................................................................................................................... 98

RUNNING A MACRO FROM THE DATABASE TOOLS RIBBON ......................................................................... 98

Contents

Page iv WWP Learning and Development LTd

CREATING A MACRO FOR AN EVENT ........................................................................................................... 99

Exercise - Creating Macros ................................................................................................................... 100

FURTHER MACROS .................................................................................................................................. 103

INTRODUCTION ........................................................................................................................................... 103

ASSIGNING A MACRO TO A CONTROL ....................................................................................................... 104

ASSIGN A MACRO TO A COMMAND BUTTON ............................................................................................. 105

ADDING A CONDITION TO A MACRO ......................................................................................................... 106

CREATING A MACRO GROUP ...................................................................................................................... 107

CREATING AN AUTOEXEC MACRO ............................................................................................................. 109

Exercise - Further Macros ..................................................................................................................... 110

EVENTS ........................................................................................................................................................ 112

INTRODUCTION ........................................................................................................................................... 112

ENSURING DATA ENTRY ............................................................................................................................. 112

AUTOMATICALLY FILLING FIELDS .............................................................................................................. 113

Exercise - Events.................................................................................................................................... 115

USING SWITCHBOARDS ......................................................................................................................... 117

INTRODUCTION ........................................................................................................................................... 117

CREATING A SWITCHBOARD ....................................................................................................................... 118

ADDING A COMMAND BUTTON TO A SWITCHBOARD ................................................................................ 119

OPENING A SWITCHBOARD AUTOMATICALLY ............................................................................................ 120

Exercise - Using Switchboards .............................................................................................................. 121

CUSTOMISING THE QUICK ACCESS TOOLBAR .............................................................................. 123

INTRODUCTION ........................................................................................................................................... 123

ASSIGNING A MACRO TO A TOOLBAR ....................................................................................................... 126

Exercise - Customising The Quick Access Toolbar ............................................................................... 127

APPENDIX A - USING ACCESS AND THE INTERNET ...................................................................... 131

INTRODUCTION ........................................................................................................................................... 131

WORKING WITH HYPERLINKS .................................................................................................................... 131

CREATING A HYPERLINK FIELD .................................................................................................................. 131

INSERTING A HYPERLINK ........................................................................................................................... 132

EDITING A HYPERLINK ............................................................................................................................... 133

DELETING A HYPERLINK FIELD .................................................................................................................. 133

EXPORTING DATABASE OBJECTS TO HTML ................................................................................................ 134

IMPORTING OR LINKING TO A HTML FILE .................................................................................................. 135

USING SHAREPOINT .................................................................................................................................... 136

Exercise - Using Access and the Internet .............................................................................................. 137

APPENDIX B – ADVANCED ACCESS SECURITY ............................................................................... 138

INTRODUCTION ........................................................................................................................................... 138

CREATING A DIGITAL SIGNATURE .............................................................................................................. 138

ADDING A DIGITAL SIGNATURE TO A DATABASE ...................................................................................... 139

DIGITALLY SIGNING AND PACKAGING A DATABASE ................................................................................. 139

USING THE TRUST CENTER ......................................................................................................................... 141

LOCKING A DATABASE ............................................................................................................................... 141

LOCKING DATABASE RECORDS .................................................................................................................. 142

Exercise - Using Access Security ........................................................................................................... 143

WWP Learning and Development Ltd Page 1

1 CONCEPTS OF NORMALISATION

INTRODUCTION 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 e.g. 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.

In this lesson, you will learn how to:

Normalise Data

Page 2 WWP Learning and Development Ltd

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.

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 over come 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.

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

1. Make each table only about one specific subject.

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

3. Each field should contain the smallest meaningful data value.

WWP Learning and Development Ltd Page 3

2 ANALYSING TABLES

INTRODUCTION 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 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.

In this lesson, you will learn how to: Analyse a table

Use relationships in splits

Use the Table Analyzer Wizard

Use the Performance Analyzer

Use the Documenter

Page 4 WWP Learning and Development Ltd

To analyse the design of tables, first open the database you wish to investigate. Click on the Database Tools tab. Click on the Analyze Table button. Read the first two explanatory pages, clicking on the Next button each time. Click on the table you want analysed. Click on the option for the Wizard to decide regarding field locations. Click on the Next button. Rename the tables. Click on the Next button. Choose whether to specify primary key(s). Click on the Next button. Set corrections if necessary. Click on the Next button. Choose whether to accept the query. Click on the Finish button.

WWP Learning and Development Ltd Page 5

USING THE PERFORMANCE ANALYZER 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.

To optimize database performance, first open the database you want to optimize. Click on the Database Tools tab. In the Analyze group, click on the Analyze Performance button. In the Performance Analyzer, select the object(s) you want analyzed. Click on the OK button. Click on each item and review the analysis notes. Press and hold down the [Ctrl] key while clicking on the suggested optimizations. Click on the Optimize button. Click on the Close button.

Page 6 WWP Learning and Development Ltd

DOCUMENTING A DATABASE 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 whole database.

To document a database, first open the database you intend to document. Click on the Database Tools tab. In the analyze group, click on the Database Documenter button. In the Documenter dialog box, click on the items on each tab that you want documented OR Click on the Select All in the All Object Types page. Click on the Options… button. In the Print Table Definition dialog box, click on the desired. After making your selections click on the OK button. Click on the OK button to start the Documenter. The Documenter will display a print preview of the report.

WWP Learning and Development Ltd Page 7

EXERCISE - ANALYSING TABLES

1. Open Train11x.

2. Open the Table Analyser Wizard. Select Next as needed and then select the Project List table. Select Next.

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

4. Rename Table1 to Project and Table2 to Client.

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

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

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

8. Select Finish.

9. Close the Microsoft Access Help window. View the tables and then close them and restore the Navigation Pane.

10. Analyse the performance of the Client and Payment tables. (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.)

11. Close the Performance Analyser.

12. Close the database file.

WWP Learning and Development Ltd Page 9

3 TRANSFERING DATA

INTRODUCTION 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.

In this lesson, you will learn how to: Import data

Link data to an Access table

Use the Linked Table Manager

Export data

Convert files

To import data from an external source, first open the database the data is to be imported into. Click on the External Data tab. In the Import group, click on the appropriate button. In the Get External Data box, locate and select the file containing the data to import. Select from the options how the data is to be imported. Click on the OK button. Follow the Wizard instructions, selecting the appropriate options and then clicking on the Next button each time. In the Import to table: box, enter a name for the table. If necessary place a check for Access to analyze the data. Click on the Finish button. Choose whether to save the import steps.

Page 10 WWP Learning and Development Ltd

LINKING DATA TO AN ACCESS TABLE You can 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.

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

To link to an Access table, first open the destination database. Click on the External Data tab. In the Import group, click on the Access button. In the Get External Data box, locate and select the database to be linked to the current database. Click on the Link to the data source by creating a linked table option. Click on the OK button. In the Link tables dialog box, click on the table(s) you wish to link. Click on the OK button. The table displays the link in the Navigation pane.

WWP Learning and Development Ltd Page 11

USING THE LINKED TABLE MANAGER 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.

EXPORTING DATA 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), 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.

To use the Linked Table Manager to correct the path of a linked table, first click on the Database Tools tab. In the Database Tools group, click on the Linked Table Manager button. In the Linked Table Manager dialog box, click on the link(s) you want to refresh. Click on the OK button. OR To change the path to a linked table, click on the Always Prompt for New Location option. Check the tables whose links are to be changed. Click on the OK button.

Page 12 WWP Learning and Development Ltd

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

Application Supported Version or Format Microsoft Access database Access 2.0, 7.0/95, 8.0/97, 9.0/2000, 10.0/2002

and 11.0/2007

dBase III, IV, 5, and 7 (Requires Borland Database Engine 4.x or later)

Paradox, Paradox for Windows 3.x, 4.x, 5.0, and 8.0 (Requires Borland Database Engine 4.x or later)

Microsoft Excel 3.0, 4.0, 5.0, 7.0/95, 8.0/97, 9.0/2000, and 10.0/Excel 2002

Microsoft Word, Rich Text Format All

Lotus 1-2-3 .wj2, .wk1, and .wk3

Delimited text files All

XML document All

WWP Learning and Development Ltd Page 13

To export an object to another program, first display the Tables list in the Navigation pane. Click on the table you want to export. Click on the External Data tab. In the Export group, click on the More button. Click on the item for the type of file you export to. Alternatively, use the right mouse button to click on the object you want to export. Select the Export item and the type of file you want to export to. Locate, and select, the file you wish to export to. In the Export dialog box, enter a name for the object and other options accordingly. Click on the OK button. Choose whether to save the export steps. Click on the Close button.

Page 14 WWP Learning and Development Ltd

CONVERTING FILES When you open a database from Access versions that are prior to Access 2000 (eg. Access 97, Access 7.0 (95), Access V2/V1), Access 2007 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 2007 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 2007. This is important where the database is used by more than one user, all of whom do not have Access 2007.

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

For Access 97 format, the Database Enhancement dialog box will be displayed, indicating the file must be upgraded to be able to use the latest features.

To convert an existing database, open the Access 2000 or 2002-2003 database you intend to convert to Access 2007 format. Click on the Office button In the Office menu, click on the Convert item. Locate, and select, the location for the converted database. Click on the Save button. In the Message box, click on the OK button to acknowledge the conversion.

WWP Learning and Development Ltd Page 15

EXERCISE – TRANSFERRING DATA

1. Open Train09X.

2. Import the Sales by Rep 2 query from the Train17x Access database in the student folder.

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 Train17x in the student data folder. Then, select OK as necessary and close the Linked Table Manager.

5. Open TrainV97. Convert TrainV97 to Access 2007 saving it as TrainV2007.

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

7. Export the Invoice Details query 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 (Invoice Details) but store it in the student data folder.

8. Close Excel.

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

10. Close the database file.

WWP Learning and Development Ltd Page 17

4 DATABASE TOOLS

INTRODUCTION The main purpose of database security is to prevent unauthorised access to, or changes to, the information contained within the database. Security can also prevent design modifications where the slightest change may cause problems which can be difficult to locate and correct. When you add database protection, you will be asked to supply a password.

ADDING SECURITY ENCRYPTION TO A DATABASE (PASSWORD PROTECTING) File encryption is security you can apply to a database which scrambles your password to protect yur 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.

To apply file encryption, first open the database you intend to encrypt in Exclusive mode. Click on the Database Tools tab. In the Database Tools group, click on the Encrypt with Password button. In the Set Database Password box enter, and confirm, the password. Click on the OK button. When the file has been closed, it will only open if the correct password is entered.

In this lesson, you will learn how to: Password protect a

Database Compact and repair a

Database

Use Name AutoCorrect

Back up a database

Page 18 WWP Learning and Development Ltd

COMPACTING AND REPAIRING A DATABASE 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.

To change or remove password encryption, open the encrypted file. Click on the Database Tools tab. In the Database Tools group, click on the Decrypt Database button. In the Unset Database Password box, enter the password. Click on the OK button.

To compact and repair a closed database, first close all databases. Click on the Office button. In the Office menu move the mouse cursor to the Manage item. Click on Compact and Repair Database. In the Database to Compact From dialog box, locate and select the database you want to compact. Click on the Compact button. In the Compact Database Into dialog box, locate and select the location for the compacted database. Enter a name for the copy. Click on Save. If you used the same name for the file, confirm the message box.

WWP Learning and Development Ltd Page 19

USING NAME AUTOCORRECT 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 since3 the last Name AutoCorrect action, it runs it again for all items in that object.

BACKING UP A DATABASE It is important to backup 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.

To use Name AutoCorrect, first click on the Office button. Click on the Access Options button. In the Access Options, click on the Current Database button in the left hand pane. In the Name AutoCorrect Options section, select the options you require. Click on the OK button.

Page 20 WWP Learning and Development Ltd

To back up a database, first open the database you wish to back up. Click on the Office button. Move the mouse cursor to Manage. Click on the Backup Database item. In the Save As dialog box, specify a name and location for the back up copy. Click on the OK button.

WWP Learning and Development Ltd Page 21

EXERCISE – DATABASE TOOLS

1. Open Train33x exclusively.

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

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

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

5. Remove the password protection. Close the database.

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

7. Open Train09x.

8. Ensure that the Name AutoCorrect option is enabled

9. Change the name of the LAST_NAME field in the Reps table to LastN and the name of the FIRST_NAME field to FIRSTN.

10. Close the Reps table, saving the changes.

11. 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. Close the Reps form.

12. Compact Train09x, make a backup of it named, Train09x and then close it.

WWP Learning and Development Ltd Page 23

5 DESIGNING ADVANCED QUERIES

INTRODUCTION In Access, queries enable you to retrieve specific data from one or more tables, even when the tables are not open. For this to happen it is obviously necessary to create some form of relationship between the tables if the database has been normalised. It is also useful to be able to make the use of the query as simple as possible for users.

Once a database has been normalised it will contain many smaller tables of related information. To combine information from these separate tables relationships can be set up so that when the tables are combined in a query to compile information from more than one table the common fields are automatically joined and the appropriate information is retrieved. If this is the case and the appropriate relationships have not been set up then a join between two tables can be created from within the query.

There are also Query Wizards which allow you to create crosstab queries (spreadsheet lookalikes), queries which can find duplicate records, and queries which will find unmatched records in related tables.

JOINING TABLES IN QUERIES When tables are joined a query the join is only effectual within the query it was created and does not affect the rest of the database.

Once created the type of join can be changed. The default join type is called an inner or equi join. This type of join will only include records in the recordset where the common fields match.

This can be changed to an outer join where the all the records in one of the tables plus all the matching fields from the other table are included in the recordset. This type of outer join can be changed to include all the records from either the left hand or fight hand of the two tables plus the remaining matching fields.

Once created the join type can be changed by double clicking on the join in the design view of the query and selecting the appropriate type required from the resulting dialog box. Outer joins are indicated in the query design view by placing an arrow on either the left or right hand side of the join line.

Access 2007 will automatically create joins between two fields on different tables when they are added to a query, if they share the same name, one is a primary key and they have the same (or compatible) data types.

When adding more than one table to a query the [Control] and [Shift] Keys can be used to make multiple selections of tables in the show table window.

Joins may be removed from a query by selecting the join with the mouse and then pressing the [Delete] key.

In this lesson, you will learn how to:

Join Tables in Queries

Work with Cross Products

Create Reverse Outer Joins

Use the Crosstab Query Wizard

Use the Find Duplicates Query Wizard

Use the Find Unmatched Query Wizard

Page 24 WWP Learning and Development Ltd

When a join is set up, the default arrangement is known as an inner join, as shown in the Join Properties dialog box which can be opened by double-clicking on the join line between two tables.

If the join is changed to a 2 or a 3 type join the join is then known as left or right outer join.

Running a query with an inner join will most likely produce different results from running a query with an outer join, depending on the data involved.

CROSS PRODUCTS When a query of more than one table is created without any relationships or joins Access has no way of matching common fields between these tables. When this happens the recordset is said to be called a cross product.

A cross product recordset will match every single record on one table with every single record on the second table. For example if you create a query with two tables and no join. If there were 100 records on one table and 40 records on the other the cross product record set would contain 4,000 records (100 * 40).

To correct a cross product query you must create an appropriate join between the two tables in the query.

CREATING REVERSE OUTER JOINS By using the is null criteria in combination with an outer join it is possible to get a record set from a query that was previously not available. Where sales are involved it would be possible to find which customers have not placed orders.

To create a join within a query, first create a query within the database you wish to work in. Move the mouse cursor over the first common field. Hold down the mouse button and drag to the second common field in the next table. The join is created between the tables.

WWP Learning and Development Ltd Page 25

An alternative to creating a reverse outer join query manually is to use the “Find Unmatched Query Wizard” (see page 28).

USING THE CROSSTAB QUERY WIZARD Crosstab queries are used to group and summarize 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.

You cannot update crosstab queries and the value in a crosstab query cannot be change in order to change the source data.

To create a reverse outer join, first open the query you want to work on in Design view. Double-click on the join line. In the Join Properties dialog box, select option 2 (an outer join). Click on the OK button. In the criteria row under the field you wish to examine, type is null. Run the query to find which of the data does not have an entry for that field.

Page 26 WWP Learning and Development Ltd

USING THE FIND DUPLICATES QUERY WIZARD 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.

To create a crosstab query, first click on the Create tab. In the Other group, click on the Query Wizard button. In the New Query box, click on the Crosstab Query Wizard option. Click on the OK button. From the list, select the table/query which contains the records you want to retrieve. Click on the Next button. From the Available Fields: list, add the field you want to use as row headings to the Selected Fields: list. Click on the Next button. Click on the field you want for column headings. Click on the Next button. In the Fields: list, click on the field you want to calculate. In the Functions: list, click on the required function. Click on the Next button. Enter a name for the query and click on the Finish button.

WWP Learning and Development Ltd Page 27

To create a find duplicates query, first click on the Create tab. In the Other group, click on the Query Wizard button. In the New Query dialog box, click on the Find Duplicates Query Wizard item. Click on the OK button. Select the table or query you want to use for the query. Click on the Next button. Add the desired fields to the Duplicate-value fields: list. Click on the Next button. Add any other required fields to the Additional query fields: list. Click on the Next button. Enter a name for the query. Click on the Finish button. Running the query displays any duplicate entry fields.

Page 28 WWP Learning and Development Ltd

USING THE UNMATCHED QUERY WIZARD The Find Unmatched Query Wizard allows you to locate and display records in one table which have no match in a related table.

You can use the Find Unmatched Query Wizard to correct the problem by updating the Customers table. However, unmatched records cannot occur if referential integrity is enforced in the table relationship.

To create a Find Unmatched query, first click on the Create tab. In the Other group, click on the Query Wizard button. In the New Query dialog box, click on the Find Unmatched Query Wizard item. Click on the OK button. In the first dialog box, select the table/query whose records you want to display. Click on the Next button. Select the table which contains the related records. Click on the Next button. If necessary, specify the joining field. Choose the field from each list. Click on the button to join them. Click on the Next button. Choose which fields from the Available fields: list to display in the query. Click on the Next button. Enter a name for the query. Click on the Finish button.

WWP Learning and Development Ltd Page 29

EXERCISE - DESIGNING ADVANCED QUERIES

1. Open Train12X.

2. Create a query in design view.

3. Add the Trainer and Project tables.

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

5. Run the query and observe the cross product result.

6. Return to the 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.

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 as Join.

13. Open Train17x.

14. Create a crosstab query from the existing Sales by Rep query. Use the Client ID field for the row headings and the Sales Rep field for the column headings. Have the calculated value be the sum of the Total Sales field. Remove any other fields from the grid.

15. Name the query Total Sales by Sales Rep, and select the option to view the query. After you have viewed the recordset, close the query.

16. Use the Find Duplicates Query Wizard to locate any duplicate records in the Client table. Select the Client Name, Address, and City fields as possible duplicate-value fields. Do not select any additional fields to show in the query results.

17. Name the query Find Duplicate Clients and select the option to view the query. Notice that two duplicate records were found. Close the query.

18. Use the Find Unmatched Query Wizard to find any projects in the Project table that have no record of payment in the Payment table. Select the Project ID field as the matching field for the two tables, if necessary. Then, have the Client ID, Course Name, and End Date fields also display in the query.

19. Name the query No Record of Payment and select the option to view the results. After you have viewed the recordset, close the query.

20. Close the database file.

WWP Learning and Development Ltd Page 31

6 CREATING RELATIONSHIPS

INTRODUCTION Tables can be joined, or related, in order to access and coordinate information in all the fields of the related tables. Joining tables is a useful way to avoid entering duplicate information in various, related tables. In addition, it allows you to create reports, forms, and queries from the related data tables and save them in the database file. Relating tables allows you to create smaller, more efficient tables that can be referenced when you need access to the data.

When you relate tables, the table from which you select a field to join is the primary table, and the second table containing the field you want to associate is the related table. The tables must have at least one common field that contains the same type of data. This common field is called the join field. The join fields in both tables must have the same or equivalent data types and, if they are Number fields, they must have the same field size. In addition, the join field in the primary table must be the primary key in order to avoid duplicate entries.

For example, the following table consists of customer names and address fields, along with a unique identification number for each customer, which serves as the primary key in the table. You can create this number or allow Access to create it for you.

ID # Names Address City State Zip

1 Smith 11692 J St. NW Washington DC 20013

2 Conrad 16 Allegheny Center Pittsburgh PA 16489

3 Kane 1012 Broadway Lexington KY 40567

4 Apple 516 Beacon Ave. Seattle WA 98051

5 Billow 9249 Cavalcade St. Houston TX 77002

You could then create a separate table consisting only of orders placed by customers. This table would also contain the field for the unique customer identification number, but not the customers’ names and addresses.

In this lesson, you will learn how to:

Use related tables

Create a relationship between tables

Set referential integrity

View subdatasheets

Delete a join line query

Printing Relationships

Page 32 WWP Learning and Development Ltd

ID # Order

1 Office Work Center

2 All-In-One Corner Desk and Hutch

3 Open-Front Steel Bookcase

4 2-Drawer Letter File

5 Executive Leather Chair, Black

By relating the two tables through the common customer identification number field, the customers’ name and address does not have to be entered for every order. All that has to be entered is the customer identification number, along with the orders.

Access includes two basic types of relationships: one-to-many and one-to-one.

A one-to-many relationship occurs when one record from the primary table matches many records from the related table (e.g., one customer record matches many order records).

A one-to-one relationship occurs when one record from the primary table matches one record from the related table. Access determines the relationship type automatically when you create the relationship.

CREATING A RELATIONSHIP BETWEEN TABLES 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 them as needed. In addition, any field name that represents a primary key is bolded in the corresponding field list.

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.

WWP Learning and Development Ltd Page 33

SETTING REFERENTIAL INTEGRITY 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:

First, 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.

Second, you cannot delete records from the "one" table if there are matching records in the "many" table.

Third, you cannot edit primary key values if related records exist.

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.

To create a relationship between two tables, first click on the Database Tools tab. Click on the Relationships button in the Show/Hide group. If necessary, click on the Show Table button. Click on the Tables tab. Click on the first table you want to relate to. Click on the Add button. Select the second table you want to relate. Click on the Add button. Add further tables as required. Click on the Close button. Drag the common field in the first table to the common field in the second table. In the Edit Relationships dialog box, click on the Create button. Repeat for any further relationships. Click on the Close button. Close the Relationships window. In the Message box, click on the Yes button.

Page 34 WWP Learning and Development Ltd

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 (which resembles a horizontal 8) indicates “many”.

Double-clicking the middle segment of any join line opens the Edit Relationships window with the selected join displayed. Double-clicking the beginning or ending segment of any join line opens the Edit Relationships window, but with no join selected. You can then use the Table/Query list to select the desired join.

VIEWING SUBDATASHEETS

Subdatasheets are datasheets nested in the primary table and display the data in joined tables. When you join tables in a one-to-many relationship, Access creates subdatasheets in the table containing the primary key. Access can also create subdatasheets for one-to-one relationships.

When tables are joined, Access inserts a column containing plus signs to the left of the first field in the primary table. Clicking the plus sign expands a subdatasheet with the data in the related table displayed. If the table contains additional joins, you can expand subdatasheets to display each related table. Access can display up to eight levels of subdatasheets.

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.

To set referential integrity for the relationship between tables, first click on the Design tab below the Relationship Tools tab. Open the Relationships window by clicking on the Relationships button. Click on 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). In the Edit Relationships dialog box, select the Enforce Referential Integrity option. Click on the OK button.

WWP Learning and Development Ltd Page 35

DELETING A JOIN LINE Deleting a join 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 join line before you can delete it. You must click the middle segment of a join line in order to select it; clicking the beginning or ending segment does not select the join line.

You can also delete a join line by right-clicking its middle segment and selecting the Delete command.

PRINTING RELATIONSHIPS

To display subdatasheets, first open the table in Datasheet view. Click on the plus sign [+] next to the record you want to expand. Display additional subdatasheets, if available. Click on any minus sign [-] to collapse the subdatasheet. Close the table.

To delete a relationship, first open the Relationships window. Click on the middle of the join line you wish to delete. Press the [Delete] key. Confirm the Message box by clicking on the Yes button. Alternatively, use the right mouse button to click on the join line. Select Delete and confirm the Message box.

Page 36 WWP Learning and Development Ltd

Once all the relationships have been defined for a database, it is often helpful to have a printed copy of the relationships.

To print the relationships diagram, first open the database you wish to document. Click on the Database Tools tab. In the Show/Hide group, click on the Relationships button. In the Relationships window, use the right mouse button to click in a blank area of the window. In the shortcut menu, select Show All. In the Tools group of the Design Ribbon, click on the Relationship Report button. The relationships are displayed as a report and can be saved as such.

WWP Learning and Development Ltd Page 37

EXERCISE - CREATING RELATIONSHIPS

1. Open Train08x.

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 in Datasheet view and view the subdatasheet for the CONCORD client. Then, collapse the subdatasheet and close the Client table.

9. Print a relationship document. Then close Print Preview, close the Report design window without saving changes.

10. 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.

11. Close the database file.

Page 38 WWP Learning and Development Ltd

7 FORM DESIGN TOOLS AND METHODS

INTRODUCTION You can create or customize a form in Design view. A form has three basic sections: Detail, Form Header/Footer, and Page Header/Footer.

The Detail section contains the information from the table or query. You create controls in the Detail section that allow you to display or enter information. Access provides a variety of control types you can add to the form to simplify the data entry process. For example, you can replace a text box with a list box or an option group so that you can select a value rather than type it during data entry. In many cases, it is quicker and easier to select a value from a list rather than to remember the value you want to use and then type it. Having a list of choices also helps to ensure the consistency of the data being entered.

The Form Header and Form Footer sections display at the top and bottom of a form in Form view. They are stationary when you scroll the Detail section, making them 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 and at the bottom of the last page. You can also place controls, including images, labels, and fields in the form header or footer.

The Page Header and Page Footer sections display at the top and bottom of the form in Design view. They do not appear in Form view. Rather, they display at the top and bottom of every page when the form is printed. Page headers and footers can contain images, lines, and text, or any other controls you want printed on 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.

In this lesson, you will learn how to: Use forms in Design view

Set the tab order automatically

Set the tab order manually

Add a form header and footer

Create a blank form

Save a form as a report

Create a PivotTable or PivotChart view

WWP Learning and Development Ltd Page 39

In Access it is also possible to save a form such that it can be printed as a report, which is of value when customers have to fill in a form which must then be printed out.

When it is necessary to summarise information from a lengthy list, you can use the PivotTable to simplify the task, rather than having to manually calculate which records meet certain criteria. Such information can be viewed in a PivotChart.

SETTING THE TAB ORDER AUTOMATICALLY 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.

SETTING THE TAB ORDER MANUALLY 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 adjust the tab order manually to reflect whatever order is best for your data entry needs.

To set the Tab order automatically, first open the form you want to set the Tab on in Design view. Click on the Arrange tab under the form Design Tools tab. In the Control Layout group, click on the Tab Order button. In the Tab Order dialog box, click on the Auto Order button.

Page 40 WWP Learning and Development Ltd

ADDING A FORM HEADER AND FOOTER The Form Header and Form Footer sections display at the top and bottom of the form in Form view. They are stationary when you scroll the Detail section, making them useful for displaying titles or instructions you want visible on the form at all times.

You can change the height of a section by dragging the bottom border of the section up or down.

You can display the Form Header and Form Footer sections by right-clicking in the form in the Design window and then selecting the Form Header/Footer command.

If you print the form, these sections appear at the top of the first page and the bottom of the last page respectively.

You can place controls, including images, labels, and fields, in the form header or footer.

To set the Tab order manually, first open the form whose tab order is to be changed in Design view. Click on the Tab Order button in the Control Layout group. In the Tab Order dialog box, click on the record selector to the left of the field you want to move. Drag the on the field selector to the new position. Click on the OK button. The tab order will now be changed when the form is opened in Form view.

To add a form header and/or footer, first open the form in Design view. Click on the Arrange tab below the Form Design Tools tab. In the Show/Hide group, click on the Form Header/Footer button. The form displays both Header and Footer panes.

WWP Learning and Development Ltd Page 41

CREATING A FORM WITHOUT USING THE WIZARD 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.

CREATING A PIVOTTABLE OR PIVOTCHART VIEW You can view any database form in PivotTable or PivotChart view using the View list. In PivotTable view, you can summarize and analyse large amounts of data. PivotChart view allows you to display data in a graphical environment. You design a PivotTable or PivotChart view by

To create a blank form, first click on the Create tab. In the forms group, click on the Blank Form button. The form is displayed in Layout view together with the Field List. To display rulers and grid, switch to Design view. If necessary, click on the Show all tables button. Select the table on which you want to base the form. Drag fields from the Field List onto the blank form where you want to place them to create the form. Click on the Save button on the Quick Access Toolbar. Enter a name. Click on the OK button.

Page 42 WWP Learning and Development Ltd

dragging fields from the Field List to preset 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.

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.

PivotTable and PivotChart views are automatically saved and updated as part of the layout of the form when you close the form. You can also display data in a table or query in PivotTable and PivotChart view.

To create a PivotChart Form, first select the table you intend to use. Click on the Create tab. In the Forms group, click on the More Forms button. From the list, select PivotTable. If necessary, click on the Design tab and click on the Field List button to display the Field List. In the blank PivotTable, drag the required field item to the Drop Row Fields here box. Drag the required field items to the appropriate Filter, Column, and Total or Detail boxes. Click on the Save button on the Quick Access Toolbar. In the Save As dialog box, enter a name, and click on the OK button.

WWP Learning and Development Ltd Page 43

To filter the data in the PivotTable, click on the list arrow in the Filter box and select the item(s) to display then click on the OK button to display data pertinent only to those items. Click on the list arrow in the Row box and select the item(s) to display then click on the OK button to display data pertinent only to those items. Click on the list arrow in the Column box and select the item(s) to display then click on the OK button to display data pertinent only to those items.

To create a PivotChart, first select the table you intend to use. Click on the Create tab. In the Forms group, click on the PivotChart button. If necessary, click on the Design tab and click on the Field List button to display the Field List. In the blank PivotChart, drag the required field item to the Drop Series Fields Here box. Drag the required field items to the appropriate Filter, Data, and Category boxes. Click on the Save button on the Quick Access Toolbar. In the Save As dialog box, enter a name, and click on the OK button.

Page 44 WWP Learning and Development Ltd

To filter the data in the PivotChart, click on the list arrow in the Filter box and select the item(s) to display then click on the OK button to display data pertinent only to those items. Click on the list arrow in the Series box and select the item(s) to display then click on the OK button to display data pertinent only to those items.

WWP Learning and Development Ltd Page 45

EXERCISE – FORM DESIGN TOOLS AND METHODS

1. Open Train18x.

2. Open the New Payment Form in Design view. Display the ruler, if necessary.

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

4. Switch to Form view and press [Tab] as necessary to view the tab order. Return to Design view.

5. Create a custom tab order. Move the Payment Date above the Amount Paid and close the Tab Order dialog box.

6. Display the form header in Design view and create a label with the text Payment Form in the left side of the form header.

7. Close the form and save it.

8 Open Train29x.

9. Select the Payment table in the Navigation Pane. Create a PivotTable using Project ID in the rows, Months in the columns (Hint: Open the Payment Date By Month group in the field list and select Months), Amount Paid in the detail field, and Credit Rating in the filter field.

10. Close the form without saving any changes. Close the database file.

WWP Learning and Development Ltd Page 47

8 AUTOMATING FORMS WITH CONTROL WIZARDS

INTRODUCTION 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.

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

In this lesson, you will learn how to: Activate the Control

Wizards

Create a Command Button

Use Navigation Control Wizards

Create a combo box

Create a list box

Create an option group

Add a logic control

Work with an ActiveX Control

To activate the Controls Wizards in order to help you create automated controls on a form, first open the database containing the form you require. Open the required form in Design view. Click the Design tab on the Ribbon. Click the Form Wizards button in the Controls group.

Page 48 WWP Learning and Development Ltd

CREATING COMMAND BUTTONS TO CARRY OUT FORM ACTIONS 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.

To add a button to carry out an action on a form, first open the database containing the form you require. Open the required form in Design view. Ensure the Control Wizards button in the Controls group is active. In the Controls group, Click on the Button button. Click in the form where you want to insert the command button. In the Command Button Wizard click on the required category in the Categories: list box. In the Actions: list, select the action you want. Click on the Next button. In the next step of the Wizard, select the form you want to open. Click on the Next button. Select the option you require for the data display. Click on the Next button. Enter text for the button or specify a picture. Click on the Next button. Provide a name for the button. Click on the Finish button.

WWP Learning and Development Ltd Page 49

CREATING COMMAND BUTTONS TO CARRY OUT REPORT ACTIONS By using the Control Wizards, a command button can be set to open a Report when clicked. The Report can be opened in Print Preview or printed directly. An action can thus be carried out on a report, without having to return to the navigation pane.

To create a button to carryout an action on a report, first open the database containing the form you require. Open the required form in Design view. Ensure the Control Wizards button in the Controls group is active. In the Controls group, click on the Button button. Click in the form where you want to insert the command button. In the Command Button Wizard click on the required category in the Categories: list box. In the Actions: list, select the action you want. Click on the Next button. Select the report you want to work with. Click on the Next button. Enter the text for the button or select a picture. Click on the Next button. Enter a name for the command button. Click on the Finish button.

Page 50 WWP Learning and Development Ltd

CREATING COMMAND BUTTONS TO CARRY OUT RECORD NAVIGATION/OPERATION 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 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.

CREATING A COMBO BOX 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.

To add a navigation command button to a form, first open the database containing the form you require. Open the required form in Design view. Ensure the Control Wizards button in the Controls group is active. In the Controls group, click on the Button button. Click in the form where you want to insert the command button. In the Command Button Wizard click on the required category in the Categories: list box. In the Actions: list, select the action you want. Click on the Next button. Enter the text for the button or select a picture. Click on the Next button. Enter a name for the command button. Click on the Finish button.

WWP Learning and Development Ltd Page 51

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

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.

CREATING A LIST BOX The control wizards can help you create a list box on a form. A list 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, unlike a combo box, you can only choose an item from the list; values not present on the list cannot 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.

To create a Combo Box, first open the required form in Design view. Click on the Design tab under form Design Tools. In the Controls group, if necessary, click on the Control Wizards button to activate it. Click on the Combo Box button. Click in the Form at the location where you want the combo box to appear. In the Combo Box Wizard, select the required option for source of the values and click on the Next button for each successive page of the Wizard. If applicable, select the table/query containing the values you want for the combo box. Select the field containing the required values. Select the sort list(s) as required. Adjust the column width as required. If applicable select the required field name. Enter a suitable label name. Click on the Finish button.

Page 52 WWP Learning and Development Ltd

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

You can set the default value for a list box by opening the property sheet and typing the desired value in quotation marks in the Default Value property box on the Data page.

CREATING AN OPTION GROUP 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 option from the set of alternatives. Therefore, option groups are best utilized when there are five or less values from which to choose. Adding more than five values to an option group can crowd a form and is less effective for 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.

The Option Group Wizard guides you through the process of creating an option group. An option group can be bound to a

To create a List Box, first open the required form in Design view. In the Controls group, click on the List Box button. Click in the form where you want the list box to be displayed. In the List Box Wizard, select the option you require. Work through the pages by clicking on the Next button each time. In the Number of columns: box, type a value for the number of columns you require. Select the required storage option. Type a label for the list box. Click on the Finish button.

WWP Learning and Development Ltd Page 53

field in a table or query. However, only the frame is bound to the field.

Within the frame, Access assigns each option a numeric value, starting with the number 1. When the option is selected, this numeric value is entered into the corresponding field. Access assigns a number because the value of an option group cannot be text.

For example, if a product comes in three colors (white, black, and green), you can use an option group in an order entry form to select the color being ordered. By default, Access assigns the number 1 to the White option, the number 2 to the Black option, and the number 3 to the Green option. You only see the White, Black, and Green options on the form, but Access actually stores the assigned numbers in the corresponding field in the table.

When you use the Option Group tool, the mouse pointer changes into a copy of the tool with a plus sign (+) above and to the left of it. The center of the plus sign (+) indicates the position of the top left corner of the option group.

Page 54 WWP Learning and Development Ltd

ADDING A LOGIC CONTROL 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.

When working with a form that contains a Yes/No field, you can create a logic control that is bound to the Yes/No field. Logic controls give a visual display of the value in a Yes/No field, such as a check box where a check mark appears when the field value is Yes and does not appear when the value is No. Another type of logic control is the toggle button, which appears “sunken” for a value of Yes and “raised” for a value of No. The logic control for a field with a null value (neither Yes nor No is chosen) appears the same as the field with a No value.

To create an option group on a form, first open the form in Design view. Ensure the Control Wizards button is activated. In the Controls group, click on the Option Group button. Click in the form where you want the option group to be displayed. In the Option Group Wizard, on each row, type the label names you require. Click on the Next button. In the next box, choose from the options for a default value. Click on the Next button. Accept, or enter, values for each row. Click on the Next button. Select from the two options and assign a field if necessary. Click on the Next button. In the next box, select the type of controls and style you require. Click on the Next button. In the final box, enter a label name for the option group. Click on the Finish button.

WWP Learning and Development Ltd Page 55

Logic controls 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.

The way in which the different 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 button Contains a dot with a Yes value and appears empty

with a No value. Check box Appears checked with a Yes value and unchecked

with a No value.

ACTIVEX CONTROLS In addition to the standard controls, such as option groups, combo boxes, and list boxes, you can add ActiveX controls to a form or report. ActiveX controls are small applications that can improve the appearance or functionality of a form or report. Other ActiveX controls are available from the Access Developer’s Edition as well as from vendors other than Microsoft. ActiveX controls have an .ocx file extension.

Make sure you activate macro, ActiveX, add-in, and VBA code detection and notification. You can use the Trust Center to help protect you from attached code attacks. The Trust Center checks for trusted sources, providing security options to ensure the best possible protection. When a potentially harmful attack is detected, the Trust Center displays a security alert in the Message Bar.

To add a logic control to a form, first open the required form in Design view. In the controls group, click on the logic control tool you want to use. Click in the form where you want the logic control to be displayed. In the Tools group, click on the Property Sheet button. In the Property Sheet, click on the Data tab. In the Control Source box, click on the list arrow. Select the field you want bound to the logic control. Close the Property Sheet. Select the label box of the logic control. Select the text. Type the required name for the control. Press the [Enter] key.

Page 56 WWP Learning and Development Ltd

ADDING AN ACTIVEX CONTROL 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.

ATTACHING AN ACTIVEX CONTROL Depending on the ActiveX control and its function, you can attach it to an existing table in Access. For example, you can attach the calendar control to a Date field in Access. The calendar will then display the date on a calendar page for the appropriate month and year.

To add an ActiveX control, first open the required form in Design view. Click on the Design tab below the Form Tools tab. In the Controls group, click on the Insert ActiveX Control button. In the Insert ActiveX Control dialog box, select the control you wish to insert. Click on the OK button. The ActiveX control is displayed on the form/report and can be manipulated as required.

WWP Learning and Development Ltd Page 57

To attach an ActiveX control to a data source, first open the form you want to use. Add the calendar ActiveX control. Select the ActiveX control. Click on the Property Sheet button. In the Property Sheet, click on the Data tab. Click on the Control Source list. Select the desired data source. Close the Property Sheet if necessary. When the form is viewed the calendar date is related to the specified field.

Page 58 WWP Learning and Development Ltd

EXERCISE - AUTOMATED CONTROLS ON FORMS

1. Open Train18x.

2. Open the New Payment Form in Design view. Display the ruler, if necessary.

3. Ensure that the Control Wizards are active.

4. Using the Combo Box tool, create a combo box for the trainers’ initials at the 3.8cm (1 1/2") mark the horizontal ruler, below the Payment Date text box.

5. Indicate that the combo box should look up values in a table as the source for the values in the list. Select Table: Trainer as the table and include the Initials field in the combo box. Accept the default sort order and column width. Store the values entered in the combo box in the Trainer Initials field and label the combo box Trainer Initials.

6. Using the List Box tool, create a list box for the credit rating at the 3.8cm (1 1/2”) mark on the horizontal ruler, below the Trainer Initials combo box.

7. Indicate that you want to type in the values for the list box. Use one column and type the values A, B, and C as separate entries. Store the values entered in the list box in the Credit Rating field and label the list box Credit Rating.

8. Reduce the height of the list box so that it displays only one line of text. Move the controls under, and left-aligned with the Trainer Initials controls.

9. Select the Project ID, Payment Date, Trainer Initials, and Credit Rating bound controls (text boxes) and size them to the narrowest size. Then, vertically space them equally.

10. Using the Option Group tool, create an option group at the 2.5cm (1”) mark on the vertical ruler, below the Total Sale text box.

11. Type Yes and No as the label names and select Yes as the default choice. Change the default value of the Yes label to -1 and the No label to 0. Store the value entered in the option group in the Recorded field. Use Option buttons as controls and select the Raised style. Enter Recorded? as the label.

12. Adjust the position of the controls to line up with those above.

13. Use the Command Button Wizard to add a command button at the bottom left of the form. The button must run the Payment Information query. (Hint: Select the Miscellaneous category in the wizard.) Have the text Payment Info appear on the command button and name the button PaymentInfo. Position the command button on the form, as desired.

14. View the form and click the Payment Info command button to run the query. Close the query and then save and close the New Payment Form.

15. Open Train30x.

16. Open the Project Form in Design view.

WWP Learning and Development Ltd Page 59

17. Insert the ActiveX calendar control onto the form.

18. Open the property sheet for the calendar control. Set the data source in the Control Source property box to the Start Date field. Close the property sheet.

19. Size the calendar control until it is approximately 3'' wide and 2'' high and position it below the existing controls, if necessary. Add a label called Start Date and centre it above the calendar control.

20. Switch to Form view and move through the records. Notice that the calendar changes to reflect the start dates.

21. Close the form without saving the changes.

22. Close the database file.

WWP Learning and Development Ltd Page 61

9 ADVANCED REPORT DESIGN

INTRODUCTION The Access Report Wizard provides you with a considerable amount of choices when setting up a report. However, you can also use the same controls that are used in forms to improve the appearance, and amount of, data displayed when the report is printed.

You can create or customize a report in Design view. 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 create 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.

When you enable the display of either header and footer section, both the header and the footer appear. You can drag the header and footer sections to size them.

In this lesson, you will learn how to:

Add report sections in Design view

Create a calculated control

Group data in a report

Create group headers and footers

Create a running summary

Insert a date/time control

Insert a page break

Change the report margins

Create a report without using a wizard

To add Headers and Footers to a report, first open the desired report in Design view. Click on the Arrange tab below the Report Design Tools tab. In the Show/Hide group, click on the Report Header/Footer button. The report now displays header and footer areas.

Page 62 WWP Learning and Development Ltd

CREATING A CALCULATED CONTROL You can add a calculated control to a form or 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 when the report or form is run.

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.

To add Headers and Footers to each page of a report, first open the desired report in Design view. Click on the Arrange tab below the Report Design Tools tab. In the Show/Hide group, click on the Page Header/Footer button. The report now displays header and footer areas for each page.

WWP Learning and Development Ltd Page 63

GROUPING DATA IN A REPORT 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 then easily find the pertinent 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.

To create a calculated control in a report, first open the required report in Design view. Create a text box control positioned where the calculated field is to be displayed. Click on the Design tab under the Report Design Tools tab. In the Tools group, click on the Property Sheet button. Click on the Data tab in the Property Sheet. Click in the Control Source box. (You can press the [F2] key to open the Zoom box to enter the expression.) Type an equal sign (=) and then type the desired calculated control expression. Select the label box to the left of the calculated control. Press the [Delete] key. If required, close the Property Sheet.

Page 64 WWP Learning and Development Ltd

CREATING GROUP HEADERS AND FOOTERS You can create a header and footer for each group that appears in a grouped report.

The header displays at the top of each group while the group footer displays at the bottom of each group.

A group footer is often used to display summary information about the group, such as total or average sales.

To group or sort data in a report, first open the report you want to format in Design view. Click on the Formatting tab under the Report Layout Tools tab. In the Grouping & Totals group, click on the Group & Sort button. In the Group, Sort and Total pane, click on the Add a group button (or Add a sort button if you are only sorting). Click on the field you want to group or sort by. To create a more complex group or sort, click on the More arrow and select the options you want. When finished setting the group or sort, close the Group, Sort and Total pane.

WWP Learning and Development Ltd Page 65

To create a group header and footer, first open the report in Design view. If necessary, click on the Group & Sort button in the Grouping & Totals group. In the Group, Sort and Total pane, click on the More arrow. Click to select with a header section. Click to select with a footer section. To add a title to the header, click on the with title click to add button. In the Zoom box, type the name of the group header. Click on the OK button. The group header is inserted.

To add a totals function for a group, display the report in Layout view. Click on the Formatting tab under the Report Layout Tools. Click on the field you want to use with a Totals function. In the Grouping & Totals group, click the Totals button and select the function you want to use. The function is added to the footer of each group.

Page 66 WWP Learning and Development Ltd

CREATING A RUNNING SUMMARY In a grouped report, you can create a running summary of the items in the group. A running summary can provide a cumulative total for all the groups above.

Often, the running summary is positioned in the group footer, which appears at the bottom of every group. For example, in a sales report grouped by region, you can create a calculated field that displays information in a running summary. After each group, a cumulative total for all the groups above appears.

To create a group summary in a report, first open the report in Design view. Click on the Design tab below the Report Design Tools tab. In the Controls group, click on the Text Box button. Click in the Group footer section. In the text box, type the expression you want to use. Alternatively, you can open the Property Sheet and type the expression in the Control Source box for the new control ( use the Zoom box by pressing the [Shift and F2] keys). Enter the description you require in the Label box. The report displays the result of the expression.

To create a running summary, first open the report you intend to use in Design view. Place a text box control in the group footer. Enter descriptive text in the label box of the new control. Enter the expression you need in the text box. Open the Property Sheet. Click on the Data tab. Click on the Running sum box. Select the option you require from the list. The report will display the values you specified.

WWP Learning and Development Ltd Page 67

INSERTING A DATE/TIME CONTROL You can insert controls that display the current date and/or time in a report. Each control updates automatically every time the report is previewed or printed. By default, a date/time control is inserted into the Report Header section. However, you can easily move it to another section.

The Date and Time dialog box inserts a control that uses the =Date() function to display the current date.

If you create a report with the Report Wizard, Access automatically inserts a date/time control in the Page Footer section with the =Now() function, formatted to show the date only in Long Date format.

INSERTING A PAGE BREAK When you print a report, Access automatically starts a new page when necessary. You can control the pagination by inserting a page break. You can insert a page break in the Group Footer section to place each group on its own page, or you can insert a page break in the Report Header section to create a separate title page for a report.

To insert a date/time control in a report, first open the report in Design view. Click on the Design tab under the Report Design Tools tab. Click on the Date & Time button in the Controls group. In the Date and Time dialog box, select the options you require. Click on the OK button. The date will be displayed at the top right of the report. Drag the date function control to the desired location.

To insert a page break, first open the report you intend to work with in Design view. In the Controls group, click on the Page Break button. Click on the report (usually in a footer) to place the page break.

Page 68 WWP Learning and Development Ltd

CHANGING THE REPORT MARGINS 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 on the Margins button.

You can also 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.

To change the report margins, first open the report in either Design or Layout view. Click on the Page Setup tab. Click on the Page Setup button. In the Page Setup dialog box, if necessary click on the Options tab. Set the margin values you require. Click on the OK button.

WWP Learning and Development Ltd Page 69

CREATING A REPORT WITHOUT USING A WIZARD You can create a report from scratch in 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.

To create a blank report, first click on the Create tab. In the Reports group, click on the Blank Report button. A blank report is displayed with the Field List on the right. Select the table from which you require fields for the report. Drag the fields you require to appropriate positions on the report. Format the report as required with headers and footers, etc. Click on the Save button in the Quick Access Toolbar. Close the report.

Page 70 WWP Learning and Development Ltd

EXERCISE - USING ADVANCED REPORT DESIGN

1. Open Train18x.

2. Create a blank report in Design view based on the Project table.

3. Change to Design View.

4. Add the Client ID field to the 2.5cm (1") mark on the horizontal ruler in the Detail section. Below the Client ID field, add the Course Name, Trainer Initials, and Students fields to the report at the 7.5cm (3") mark on the horizontal ruler in the Detail section.

5. Display the report header and footer. Using the toolbox, add a label to the left side of the report header. Enter the text Client Information.

6. Preview the report. Then, close the report and save it as Client Info.

7. Open the Project Information Report in Design view.

8. Add a calculated control below the Trainer Initials text box to calculate the profit margin of each project. The calculation should use the following formula: =[Total Sale]*.08. Format the calculation as currency. Position the calculated control under the Trainer Initials text box. Change the text in the label to Profit Margin. If necessary, resize the label to view all the text, and then, position it under the Trainer Initials label.

9. Preview the report. Notice the profit margin calculation. Then, switch back to Design view.

10. Sort the report by the Trainer Initials field in an Ascending order and a secondary sort by Project ID in Ascending order. (Hint: Use the first and second rows of the Sorting and Grouping dialog box.) For the Trainer Initials field, include a group header and group footer, group on each value, and keep the whole group together on one page.

11. Move both Trainer Initials controls to the Trainer Initials Header section. Move the Profit Margin controls up directly below the Total Sale controls.

12. Create a horizontal line above the Project ID controls from 0cm (0”) to 10cm (4”) on the horizontal ruler. Then, reduce the size of the Details section by moving the bottom border just under the Profit Margin controls.

13. 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.

14. Create a new calculated control 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. The calculation should use the following formula: =Sum([Total Sale]*.08). Format the calculated control as currency. Change the text in the label control to Total Profit.

WWP Learning and Development Ltd Page 71

15. Create another horizontal line in the Trainer Initials Footer section, above the Total Profit controls, and from 0cm (0”) to 10cm (4”) on the horizontal ruler. Then, preview the report.

16. Switch back to Design view and change the Total Profit calculated control to a running summary for each group.

17. Preview the pages of the report. Notice that the total profit calculation is now cumulative for each trainer.

18. Switch back to Design view. Display the Report Header/Footer section.

19. Insert the date only using the default date format Move the date control to the Page Footer section.

20. Adjust the top and bottom page margins to 2cm (.75").

21. Preview the report to see the new margins. Notice that the date appears on each page of the report. Close the report, saving the changes.

22. Use the Label Wizard to create labels based on the Trainer table. Use the Avery L7163 labels and the default font and colour settings. Include the First Name and Last Name fields, separated by a space on the same line. Sort the labels by the Last Name and First Name fields. Use Labels Trainer as the name of the report.

23. Close the labels report after viewing it.

24. Close the database file.

WWP Learning and Development Ltd Page 73

10 USING CHARTS

INTRODUCTION Charts and graphs enhance data presented n forms and reports by summarizing and illustrating information in a graphical form. Using graphs and charts, readers can easily analyse trends and comparisons. You can create a chart from data in a table or query using the Chart Wizard.

The Chart Wizard assists you in creating charts quickly. 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.

Access includes a number of charts from which you can choose. The Chart Wizard provides a description of each chart type to assist you in selecting the appropriate type for the data you are using.

In this lesson, you will learn how to: Create a chart

Change the chart type

Add a chart to a form or report

Format chart objects

Change the chart title

Format the chart title

Add data labels to a chart

Page 74 WWP Learning and Development Ltd

To create a chart, first create a blank form or report if you are creating a free standing chart, otherwise if you want to embed the chart in an existing form or chart, open the form/report in Design view. Click on the Design tab. In the Controls group, click on the Insert Chart button. Drag the mouse to create a rectangle the size of the chart you intend to create. In the Chart Wizard dialog box, click on the table or query you wish to use in the chart. Click on the Next button. In the Available fields: list, select the field containing the data you want to use and transfer it to the Fields for chart: list. Click on the Next button. Click on the type of chart you want to display. Click on the Next button. Make any layout changes you want. Click on the Next button. Enter a name for the chart and choose whether to display a legend. Click on the Finish button.

WWP Learning and Development Ltd Page 75

CHANGING THE CHART TYPE After creating a chart, you may decide to display the data more effectively with another type of chart. You can change the chart type in the Microsoft Graph window by double-clicking on the chart you want to change. Access includes a number of chart types from which you can choose.

FORMATTING CHART OBJECTS Chart objects are the elements which make up the chart. Any one of a data series, a title, a legend, or an axis is an element. When any one of these is selected it can be formatted.

To change a chart type, first open the form/report in Design view. Double-click on the chart. Click on the Chart type button list arrow. OR Click on the Chart menu and select Chart Type… Select the type of chart you want. You can also use the Datasheet below the chart to change the values if necessary.

To select a chart object, open the report/form in Design view. Double-click on the chart. Either click on the object OR Click on the Chart Objects list arrow. Click on the item to select it.

Page 76 WWP Learning and Development Ltd

To format a chart object, first open the required form or report in Design view. Double-click on the chart object you want to format. Click on the tab pertinent to the options you want to use. Select the options to apply. Click on the OK button.

To customise a chart, first open the required report or form in Design view. Double-click on the chart. Click on the Chart menu. Click on the Chart Options… item. Click on the tab for the item you want to customise. Make the changes you want. Click on the OK button.

WWP Learning and Development Ltd Page 77

FORMATTING THE CHART TITLE You can format the chart title, changing the pattern, font, and alignment of the chart title. The pattern of the chart title controls the type of border around the title, if any, and the background color of the title.

The font controls the appearance of the chart title text, such as font type, style, and size. The alignment of the chart title controls where the title text appears relative to the chart, as well as the orientation of the title text.

To change the view of a 3-D chart, first open the required form or report in Design view. Double-click on the chart. Click on the Chart menu. Click on 3-D View… Change the elevation or rotation as required. Change the chart height if required. Click on the OK button.

To change or format the chart title, first open the required form/report in Design view. Double-click on the chart. Click on the chart title and then click again to enter the edit mode. Change the title as required. To format the chart title, click on the title once. Click on the format menu. Click on Selected Chart Title… In the Color dialog box, click on the appropriate tab. Make changes as required. Click on the OK button.

Page 78 WWP Learning and Development Ltd

ADDING DATA LABELS TO A CHART You can add data labels to a chart which identify the data displayed in the chart. They differ from the legend in that they are placed on the pieces of the chart, rather than in a key beside it. Data labels can display amounts and percentages from the chart data. You can use data labels to present a more detailed and effective chart.

To display data labels, first open the form or report containing the chart you wish to modify. Double-click on the chart. Click on the Chart menu. Click on Chart Options… Click on the Data Labels tab. Select the option(s) you require. Click on the OK button.

WWP Learning and Development Ltd Page 79

EXERCISE - USING CHARTS

1. Open Train27x.

2. Display the Reports object list in the Navigation pane.

3. Open the Project Information Report in Design view.

4. Extend the Report Header down to 7 cm. The new chart will be located in this section.

5. Using the Chart Wizard (Hint: click the Insert Graph button in the Control group of the Design tab on the Ribbon), select the Sales table, and include the Cost field to create a Pie Chart. Select None instead of Sum of Cost (Hint: double click the field and change it). Choose No Field in the Report fields and Chart fields. Accept the default title for the chart and select not to display a legend. Select to open the report with the chart displayed on it.

6. Change the chart type to Column. Select the Clustered Column sub-type, if necessary.

7. Change the chart title to Sales Reps.

8. Apply the Bold Italic style and a 12 point font size to the chart title.

9. Add data labels that show the actual values represented by the chart.

10. Size and position the chart as necessary to view the values.

11. Preview the report. 12. Close and save the report as Sales Report. 13. Close the database file.

WWP Learning and Development Ltd Page 81

11 USING SUBFORMS/SUBREPORTS

INTRODUCTION You can display a form/ report within a form/ report. The main form/ report includes information from one table and the subform/ subreport includes information from a second, related table.

You can show a form or report within a form/ report to more effectively show the linked data from tables with one-to-many relationships. The main form/ report and the subform/ subreport are linked by a common field between the tables. The main form/ report represents the one side of the one-to-many relationship and the subform/ subreport represents the many side.

When viewing a record in the main form/ report (one side relationship), the subform/ subreport displays the related records from another table (many side relationship).

Subform data can be displayed in either Form view (one record at a time) or Datasheet view (many records displayed at once), while subreport data can only be displayed in Print Preview. You can also create and display subform data in a PivotTable or PivotChart.

You can add any number of subforms/ subreports to a form/ report as well as add a subform/ subreport within another subform/ subreport. You should keep in mind that the purpose of a form/ report is to make viewing and entering data easier. You can avoid cluttering the form/ report (which can cause confusion) by positioning the subform(s) or subreport(s) carefully, assigning a different background color to each, and removing any unnecessary items, such as scroll bars. Viewing the properties of the subform/ subreport is helpful when considering these options.

The SubForm/ SubReport Wizards provide the easiest method for creating a subform subreport. If you choose not to use the SubForm/ SubReport Wizards, you will need to design a form/ report and then insert it into another form/ report. You may not want to use the wizard if you are designing a subform/ subreport that is very different in appearance from the form report the wizard produces.

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.

In this lesson, you will learn how to:

Work with subforms/subreports

Create a subform/subreport

Edit the layout of a subform

Display a subform in Datasheet view

Display a subform total

Page 82 WWP Learning and Development Ltd

To create a subform, first open the form you want add a subform to in Design view. Click on the Design tab under the Form Design Tools tab. In the Controls group, click on the Subform/subreport button. Drag to create a frame for the subform. In the Subform Wizard, select the data options you want. Click on the Next button. Select an option for the fields which link the form. Click on the Next button. Enter the name for the subform. Click on the Finish button. The subform is displayed relating to the main form.

WWP Learning and Development Ltd Page 83

EDITING THE LAYOUT OF A SUBFORM In order to improve the efficiency or appearance of a subform/ subreport, you can change its layout the same way you would change the layout of a form/ report. In Design view for the main form/ report, the subform/ subreport is a control that you can move, resize, align, add, and delete as you would any other control. Since the subform/ subreport control contains a form/ report, you can open it in Design view and make any editing changes to its controls. Any changes to the layout of the subform/ subreport are performed in Design view.

You can open a subform into a separate Design window by right-clicking the desired subform and then selecting the Subform in New Window command from the shortcut menu.

DISPLAYING A SUBFORM IN DATASHEET VIEW You can display a subform in Datasheet view. This option allows you to view many subform records at once, rather than viewing them one at a time in Form view. Since the benefit of using subforms is to display the “many” side of a one-to-many relationship, Datasheet view is sometimes preferred.

To edit the layout of a subform,first open the form in Design view. Select the control you intend to edit. Make the necessary changes. Save and close the form.

To display a subform in Datasheet view, first open the form in Design view. Click on the subform to select it. In the Views group, click on the View list arrow. Click on Datasheet view. The subform data is displayed in Datasheet view.

Page 84 WWP Learning and Development Ltd

DISPLAYING A SUBFORM TOTAL 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:

Control Name Expression Result Total =[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

Discount =[Price]*.15 Multiplies the Price field of an item by a constant discount of 0.15

Date =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.

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]

WWP Learning and Development Ltd Page 85

To display a subform total in the main form, first open the required form in Design view. Click on the Design tab under the Form Design Tools tab. In the Controls group, click on the Text Box button. Click in the form where you intend to place the control. Select the label and enter the required text. Click on the text box. If necessary use the Property Sheet to enter an expression for the Control source to relate to the subform control to be used. Alternatively, enter the expression directly in the text box. Close the Property Sheet. The form view shows the total for each order in turn.

Page 86 WWP Learning and Development Ltd

EXERCISE - USING SUBFORMS/SUBREPORTS

1. Open Train28x.

2. Open the Invoice Form in Design view.

3. Use the SubForm Wizard to create a subform in the bottom center 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.

WWP Learning and Development Ltd Page 87

12 WORKING WITH INDEXES

INTRODUCTION 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.

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 88 WWP Learning and Development Ltd

CREATING A SINGLE FIELD INDEX 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.

To view indexes, first open the database you want to work with. Open the table, in Design view, whose indexes you wish to view. Click on the Design tab under the Table Tools tab. In the Show/Hide group, click on the Indexes button. The Indexes box is displayed.

To create a single field index, first display the required table in Design view. Click on the field you require to be an index. In the Field Properties pane, click on the list arrow of the Indexed box. Select the option you require.

WWP Learning and Development Ltd Page 89

CREATING A MULTIPLE FIELD INDEX 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.

To create a multiple field index, first open, in Design view, the database table you wish to work with.

Click on the Design tab under the Table Tools tab.

In the Show/Hide group, click on the Indexes button.

Click in the first blank field in the Index Name column.

Type the name of the index.

In the Field Name column, click on the list arrow.

Click on the field you want to index.

In the Sort Order column, click on the list arrow to choose the sort you require.

Select the next blank box in the Field Name column.

Select the field you want to index.

In the Sort Order column, click on the list arrow to choose the sort you require.

Repeat adding more fields as required to the index.

Close the Indexes box.

Page 90 WWP Learning and Development Ltd

DELETING AN INDEX 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.

To delete an index first open, in Design view, the database table you wish to work with.

Click on the Design tab under the Table Tools tab.

In the Show/Hide group, click on the Indexes button.

Click on the row selector to the left of the row containing the index you intend to delete. Press the [Delete] key. Close the Indexes box.

WWP Learning and Development Ltd Page 91

CREATING A MULTIPLE FIELD PRIMARY KEY 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.

Therefore, the item numbers may not be unique. Thus, 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,

which allows each item to appear only once on each order.

To create a multiple field primary key, first open the required database table in Design view. If necessary, click on the Design tab below the Table Tools tab. Click on the row selector to the left of the row containing the first field for the primary key. Hold the [Ctrl] key and click on the row selector for the second primary key field. In the Tools group, click on the Primary Key button. Click on the Indexes button to see the multiple primary key.

Page 92 WWP Learning and Development Ltd

EXERCISE - WORKING WITH INDEXES

1. Open Train31x.

2. Open the Invoice table in Design view.

3. Index the Client ID field, allowing duplicates.

4. Open the Indexes window.

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.

WWP Learning and Development Ltd Page 93

13 WORKING WITH MACROS

INTRODUCTION 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.

Macro commands in Access consist of an action and its arguments. The action is the task to be performed, such as opening a form. The arguments determine the specifics for the action, such as which form to open.

You create a macro in Access using the Macro Builder window. This window has two panes. The upper pane, called the Action pane, contains a design grid. The design grid can contain up to five columns. The Action, Argument, and Comment columns are always displayed. The Action column contains one of the many available macro commands. The Arguments column is for display only and can be hidden by clicking on the Arguments button in the Show/Hide group. Arguments must be entered in the Action Arguments pane. In the Comment column, you can type a description of the action.

You can also display the Macro Name and Condition columns. The Macro Name column contains a name for a macro that can be referred to during events, such as clicking a command button. You can execute a macro conditionally by adding a statement to the Condition column.

The lower pane, called the Action Arguments pane, contains the arguments. The arguments listed change, depending on what action is selected. The right side of the Action Arguments pane displays helpful information about the selected action or action argument.

In this lesson, you will learn how to: Work with macros

Open the Macro Builder window

Create a macro

Assign an argument to an action

Save a macro

Use single step mode for testing

Run a macro

Edit an existing macro

Create a macro for an event

Page 94 WWP Learning and Development Ltd

CREATING A MACRO A macro includes actions. You place each action in a separate row in the design grid in the order in which they are to be performed. For example, a Maximize command maximizes the window opened in the step immediately preceding it.

You use the Comment column to enter a description of the action to be performed. This field can contain up to 255 characters. While comments are optional, it is beneficial to enter a description of the action. This field is helpful if you want to modify the macro at a later time.

To open the Macro Builder window, first open the database you intend to work with. Click on the Design tab. In the Other group, click on Macro. The Macro Builder window is displayed.

To create a macro, first click on the Create tab. In the Other group click on the Macro button. In the Macro builder, select the first blank field in the Action column. Click on the list arrow. Click on the action you want to use. Press the [Tab] key (or the [Enter] ) key twice. In the Comments column, if required, enter a comment to explain the action. Enter further actions and comments as required. When you close the Macro builder, you will be prompted to save the macro.

WWP Learning and Development Ltd Page 95

ASSIGNING AN ARGUMENT TO AN ACTION Most actions have a default list of available arguments. For action arguments without a list, you can type the argument into the argument field. You can enter up to 255 characters into the argument field.

Some arguments are required. For example, you must select the Form Name argument for the OpenForm action. Other arguments, such as Filter Name, are not required for the OpenForm action. If a required argument is missing, the macro stops when the action containing the missing argument is encountered.

In some cases, a default argument is used. For example, the View argument defaults to Form for the OpenForm action. Other arguments are ignored if they are not selected.

With forms, you can also specify a Where Condition argument. This argument acts as a filter, without using an actual query. For example, the argument [Credit Limit] = 1000 limits records to those with a credit limit of 1000. You can type the condition directly into the argument box or click the Build button in the argument box to open the Expression Builder dialog box.

Access displays a helpful message explaining the selected argument to the right of the argument boxes. If you press the [F1] key while the insertion point is in the Action Arguments pane of the Macro Builder window, a help window for the argument opens with additional information.

SAVING A MACRO 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 Navigation pane.

To assign an argument to an action, first open the required macro in Design view. Select the action in the Action column to which you want to assign an argument. Select the applicable argument in the Action Arguments pane. Type the argument or select the corresponding list arrow. If applicable, select an argument from the list. Add other arguments to the action as required.

Page 96 WWP Learning and Development Ltd

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.

USING SINGLE STEP MODE FOR TESTING A MACRO 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, action name, and selected arguments.

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 Builder 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 Builder window. After you make the changes to a macro, you should retest it.

To save a macro, first create the required macro. Click on the Save button on the Quick Access Toolbar. In the Save As dialog box, enter a name for the macro. Click on the OK button.

WWP Learning and Development Ltd Page 97

RUNNING A MACRO You can run a macro from the Navigation pane by selecting the macro name and using the right mouse button to click, thus opening the shortcut menu, and clicking on the Run item.

You can also run the macro when in the macro is displayed in Design view.

A warning box opens if required arguments are missing or if the macro cannot run for any reason.

To test a macro step by step, first open the macro you want to run in Design view. Click on the Design tab below the Macro Tools tab. Click on the Single Step button. Click on the Run button. Click on the Step button to perform the first action in the macro. Repeat as necessary until the macro finishes. If the macro encounters an action it cannot perform, a message box is displayed stating the action it could not carry out. Click on the Stop All Macros button to stop the macro. When you have finished testing and correcting the macro, click on the Single Step button to de-activate step mode and allow the macro to run normally.

To run a macro from Design view, click the Run button in the Tools group of the Design tab on the Ribbon. 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 98 WWP Learning and Development Ltd

EDITING AN EXISTING MACRO After you have created a macro, you may decide to add or delete existing actions or change actions or action arguments. In the Macro Builder window, you can cut, copy, and paste to edit a macro. You can also insert and delete rows.

After you make the desired changes, you must save the macro to save the changes. It is a good idea to test the edited macro using single step mode. You must remember to disable single step mode after testing a macro.

RUNNING A MACRO FROM THE DATABASE TOOLS RIBBON You can run a macro using the Database Tools 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.

To edit an existing macro, in the Navigation pane, use the right mouse button to click on the macro you want to edit. From the menu, select Design view. Change the actions and arguments you want to change. To insert a row, click on the row where you want the new row to be located. In the Rows group, click on the Insert Rows button. To delete a row, click on the row you want to be deleted. In the Rows group, click on the Delete Rows button. Click on the Save button on the Quick Access Toolbar. Click on the Close button.

To run a macro from the Database Tools ribbon, first click on the Database Tools tab. In the Macro group, click on the Run Macro button. In the Run Macro dialog box, enter or select the macro you want to run.

WWP Learning and Development Ltd Page 99

CREATING A MACRO FOR AN EVENT You can create a macro using the Macro Builder from the Property Sheet. This method is used when you want to associate a macro with an existing object or control. You can also create macros using the Expression Builder, or in VBA code if you wish to.

Creating a macro using this method requires that you associate the macro with an event, such as On Click or On Close. When you select an Event property, the Build button appears. The Build button gives you access to the Macro Builder.

To create a macro associated with an object, first open the required form/report in Design view. Click on the object you intend to associate the macro with. Click on the Design tab below the Form/Report Design Tools tab. In the Tools group, click on the Property Sheet button. In the Property Sheet, select the Event tab. Select the desired Event property. Click on the Build button. In the Choose Builder box, click on Macro Builder. Click on the OK button. Create the macro, saving and naming it. The macro is now linked to the object and will run when that event occurs.

Page 100 WWP Learning and Development Ltd

EXERCISE - CREATING MACROS

1. Open Train34x.

2. Create a new macro. Enter the following actions and comments:

Action Comment

OpenForm Opens the Invoice Form

MoveSize Sizes the Invoice Form and positions it at the top of the window

OpenForm Opens the Payment Form in Datasheet view

MoveSize Sizes the Payment Form and positions it below the Invoice Form

3. Enter the following arguments for each action:

Action Arguments

OpenForm Form Name: Invoice Form Data Mode: Read Only

MoveSize Right: 0cm (0”) Down: 0cm (0”) Width: 15.5cm (6”) Height: 7.5cm (3”)

OpenForm Form Name: Payment Form View: Datasheet Data Mode: Read Only

MoveSize Right: 0cm (0”) Down: 7.5cm (3”) Width: 15cm (6”) Height: 5cm (2”)

4. Save the macro as Open Invoice/Payment Forms.

5. Enable single step mode and run the macro to test it.

6. Correct any errors, close the forms and return to the macro Design view.

7. Edit the macro. In the second step, MoveSize, change the Height argument to 5cm (2”). In the fourth step, MoveSize, change the Down argument to 5cm (2”).

8. Disable single step mode then Save the macro and close the Design window.

9. Run the Open Invoice/Payment Forms macro using the Run Macro button in the Database Tools Ribbon.

10. Close the forms.

11. Create a new macro that closes the Invoice Form and the Payment Form (Hint: you will need two separate actions for this). Save the macro as CloseForms and close the macro design window.

WWP Learning and Development Ltd Page 101

12. Open the Invoice Form in Design view.

13. Assign to the Close Forms command button, the CloseForms macro created previously (Hint: open the Property Sheet and look for the OnClick event).

14. View the form and test the command button. The Payment form should open.

15. Close all open forms and save the changes.

WWP Learning and Development Ltd Page 103

14 FURTHER MACROS

INTRODUCTION 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.

Property sheets display the properties of a selected object. They have several tabs including Format, Data, Event, and Other that list the properties by group. The groups are the same for every property, but the items in the group change depending on the type of object selected. The All page displays all the properties in a single list.

The Format properties allow you to control the appearance of an object, such as colour, font, size, and borders. These properties change automatically when you make changes to an object. The Data properties allow you to specify the source of the data and control items, such as default values. The Event properties allow you to control when an action occurs. The Other properties contain items that do not fit into the other three categories, such as the name of a control when used in a macro or text that appears in the status bar.

In this lesson, you will learn how to: Assign a macro to a

control

Assign a macro a command button

Add a condition to a macro

Create a group macro

Create an Autoexec macro

Page 104 WWP Learning and Development Ltd

ASSIGNING A MACRO TO A CONTROL 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 menu structure. 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 menu commands.

To assign a macro to a control, first open the desired form in Design view. Click on the control you want to attach a macro to. If necessary, click on the Property Sheet button to display the Property Sheet. In the Property Sheet, click on the Event tab. Select the required property. Use the list arrow to select the macro you want to use. If required, close the Property Sheet. When the form is open, clicking on the designated control will run the macro.

WWP Learning and Development Ltd Page 105

ASSIGN A MACRO TO A COMMAND BUTTON Command buttons are controls to which you can assign actions. They are often used to run macros in 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 view using the Command Button tool in the toolbox. After you create the command button on the form, you set the properties, such as the event property to initiate the action and the text or picture to appear 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.

To create a command button that is attached to a macro, first open the required form in Design view. Click on the Design tab below the Form Design Tools tab. In the Controls group, click on the Button button. Click in the location where the button is to be located. If necessary, open the Property Sheet. Click on the Event tab. Select the required property. Click on the list arrow and select the required macro. Click on the All tab. In the Name box, enter a suitable name. In the Caption box, enter the text to be displayed on the button. If necessary, close the Property Sheet. When clicked on, the button in the form will operate the macro.

Page 106 WWP Learning and Development Ltd

ADDING A CONDITION TO A MACRO You can add a condition argument to a macro. An argument acts very much like a filter. Just as a filter displays only the records that meet the condition, the argument only performs the macro when the condition is met.

Before you can add a condition to a macro, you must display the Condition column in the Macro Design window. The Condition column appears to the left of the Action column in the upper pane of the Macro Builder window. You can type a condition or use the Expression Builder dialog box to create the expression.

If you type an 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 point. 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, 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.

Since you enter the condition in the Condition column in the Macro Builder window, you do not need to include the word IF in the statement. Access assumes the statement is a condition. If the condition is true, Access performs the corresponding action in that row. If the condition is false, Access does not perform the action.

You can also create an expression using the Expression Builder when you display the Condition column by right-clicking in the Condition column and then selecting the Build command, by right-clicking in the Action Arguments pane and then selecting the Build… command, or by clicking the Builder button on the Macro Design ribbon.

If the condition is true, you can have Access perform more than one action by entering an ellipsis (...) in the Condition column in the Macro Builder window. Access performs the action on the same row as the condition and all rows thereafter that contain an ellipsis.

WWP Learning and Development Ltd Page 107

CREATING A MACRO GROUP You can place multiple macros on the same macro sheet. This option, called grouping macros, has several advantages. The most obvious advantage is that it reduces the number of macros that appear in the window. More importantly, it allows you to organize your macros by grouping related macros together onto a single macro sheet. For example, if you created several macros that are related to one form, you can group all of them together on one macro sheet.

Before you can create a group macro, you need to display the Macro Name column in the Macro Design window. The Macro Name column appears to the left of the Action or Condition column, if it is displayed. You can type the macro name directly into the appropriate field in the Macro Name column.

Like any other macro, a group macro must be saved with a name. You should make sure that the group macro name is descriptive enough to indicate its contents. This helps other users know what macros are contained in the group macro. For example, if all the macros relate to the Orders form, you could name the group macro Order Form Macros.

When macros are grouped, you can still refer to individual macros. To refer to an individual macro in a group, you can use its group and macro name in the format Groupname.Macroname.

If you have already created macros, you can cut and paste them into a new group macro sheet or edit an existing macro sheet.

To add a condition to a macro, first open the required macro in the Design view. If necessary, click on the Design tab under the Macro Tools tab. In the Show/Hide group, click on the Condition button. Click in the Condition box. Type the condition in the box.

Page 108 WWP Learning and Development Ltd

To create a macro group, first display the macro you want to use in Macro Design view. Click on the Design tab. Click on the Macro Names button. Click in the first blank field in the Macro Name column. Type a name for the macro. In the Action column, select the required action. Insert a comment if required. In the Action Arguments pane, select options as required. Continue for other groups as necessary. Save and close the macro.

WWP Learning and Development Ltd Page 109

CREATING AN AUTOEXEC MACRO 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.

To create an Autoexec macro by renaming an existing macro, first display the Macros list in the Navigation pane. Use the right mouse button to click on the macro you intend to rename. Click on the Rename item in the shortcut menu. In the box, type Autoexec. Press the [Enter] key. The next time that database is opened the macro will run automatically.

Page 110 WWP Learning and Development Ltd

EXERCISE - FURTHER MACROS

1. Open Train35x.

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. Close and save the form.

8. 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. Close the form.

9. Open the Balance macro in Design view.

10. Add a condition to the Balance macro so that the macro only runs when the balance due is greater than 0. Enter the following condition for the macro: Forms![Payment Form]![Balance Due] > 0.

11. Close the macro Design and save the changes.

12. 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 that 0). Move through the next several records and notice that the message box only opens when a balance is due. Close the form window.

13. Open the Project form in Design view.

14. Create a command button without using the wizard. Place it in the lower left corner of the form. Assign the View Report macro to the command button so that it runs when the mouse button is clicked. Enter the text Print Project Report in the Caption property box. Resize the button to display all the text, if necessary.

15. Close and save the Project Form. Open the Project Form in Form view and test the Print Project Report command button. Notice that the form prints. Close the form.

16. Create a group macro. Enter the following names, actions, and arguments in the Macro Design window:

WWP Learning and Development Ltd Page 111

Macro Name Action Argument Open the form OpenForm Form Name: Client Information Form Print the Report OpenReport Report Name: Client Information

Report View: Print

Open the Trainer table OpenTable Table Name: Trainer

17. Save the macro as Client Macros. Close the macro Design window.

18. Test then three Client Macros using the Run Macro button in the Database Tools Ribbon.

19. Close the database file.

Page 112 WWP Learning and Development Ltd

15 EVENTS

INTRODUCTION Each control, section and entire object on a form or report has properties. It is the event properties for each of these that can be used to attach either modules or macros. This enables automation, data validation or various other procedures to be started when certain events occur.

An event is a specific action which occurs on or with a certain object. Clicking on a button is an event, in this case known as the On Click event.

Other events include On Close which is when a form or report is closed and is removed from the screen.

If an event is to cause a macro to run, the settings must be made in the Event page of the Property Sheet which can be opened by clicking on the Property Sheet button in the Tools group of the Design ribbon. The Property Sheet can be left open while dealing with different objects in the form/report.

When a macro/module attached to a event property will actually run will depend on the event property itself.

ENSURING DATA ENTRY By using a conditional macro a field can be tested to see if it contains a correct value. Although this can be done using Validation Rules and the required properties by using a macro the response to a incorrect value can be customised to not only come up with an error message, but also return the user to the appropriate field.

Using the MsgBox action can create a custom message box and the GoTo Control action can be used to return the user to the appropriate field.

In this lesson, you will learn how to: Use Event Properties

Use macros to ensure data entry

Use macros to automatically fill in fields.

WWP Learning and Development Ltd Page 113

Finding the appropriate event to attach a macro is a 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.

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 ahs 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.

To attach a macro which will ensure data has been entered on a form, first open the required database. Click on the Create tab. Open the required form in Design view. Ensure the Property Sheet is open. Select the object to be used. In the Property Sheet, click on the Event tab. Click on the Before Update property. Click on the Build… button. In the Choose Builder box, click on Macro Builder. Click on the OK button. In the Show/Hide group, click on the Conditions button. Enter the necessary condition. In the Action column, select the action you want from the list. Enter further conditions, actions, comments and arguments, as required. In the Close group, click on the Close button. In the message box, click on the Yes button. When the form is run, if the designated field is not filled, the user will be stopped form saving the record until the discrepancy is rectified. Alternatively, a macro can be created and then attached to the required property rather than being attached directly to the property.

Page 114 WWP Learning and Development Ltd

By using the SetValue action in a macro a control or a controls properties can be set. Then using the Goto control action the filled control can be bypassed.

To create, and add, a conditional macro to automatically fill a field, first open the required database. Click on the Create tab. Click on the Macro button. Click on the Conditions button. Add the required conditions to set the test for the contents of the field. Add any other actions, arguments and comments as necessary. Close, and save, the macro. Open the required form in Design view. Click on the control to be used for the macro. If necessary, open the Property Sheet. Click on the Before Update property. From the list, select the macro to be used. Save the form design. When entry is made in the specified form field, subsequent field(s) will automatically be completed.

WWP Learning and Development Ltd Page 115

EXERCISE - EVENTS

1. Open Train10x.

2. Open the New Payments form in Design view.

3. Create a macro that will not allow the macro 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:

Condition Action Arguments

[Amount Paid] <=0 CancelEvent

… MsgBox 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]

4. Close and save the macro as CheckPaid.

5. Attach the macro to the form’s BeforeUpdate property.

6. View the form.

7. Add a new record as follows:

Project ID: 1023

Payment Date: 6/6/95

Amount Paid: 0

Balance Due: 200

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 and then close the database.

WWP Learning and Development Ltd Page 117

16 USING SWITCHBOARDS

INTRODUCTION 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. You can use the Switchboard Manager, or start with a blank form.

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.

You can also create a switchboard in Design view using a blank form. When you create a form 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.

In this lesson, you will learn how to: Open and use a

switchboard

Create a switchboard form

Add a command button to a switchboard

Set startup options

Page 118 WWP Learning and Development Ltd

CREATING A SWITCHBOARD 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.

Because you do not want the switchboard to look like a typical form, you should set the 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

You may also want to size the switchboard form so that it covers the entire screen. To further enhance the switchboard form, you can change the background color and add text and graphics.

To create a switchboard, first open the desired database. Click on the Database Tools tab. Click on the Switchboard Manager button. Click on the Yes button if asked if you want to create a switchboard. In the switchboard Manager box, click on the Edit… button. In the Switchboard Name: box, type a name for the main page. Click on the New… button. Enter text for the button. In the Command: box, click on the list arrow. Select a command. In the Form: box, click on the list arrow. Select the form you wish to be displayed. Click on the OK button. Continue adding new buttons as required for the switchboard. Click on the Close button. Click on the Close button.

WWP Learning and Development Ltd Page 119

ADDING A COMMAND BUTTON TO A SWITCHBOARD Once you have created the switchboard form, you add controls, such as command buttons, to it. As your database changes, you can modify the switchboard, as necessary. To improve the appearance of your switchboard, you can add labels and graphics, change object colors 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.

When a control performs two or more functions, you should assign the control’s action to a macro. As with single function controls, you can use the Control Wizard. This method of assigning control actions to macros is the most common because many switchboard controls perform two actions, such as opening a form and closing the switchboard.

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.

To add a command button to a switchboard, first open the switchboard form in Design view. Ensure the Control Wizard button is active. Click on the Button button. Click in the form where you want to insert the command button. Select the required category from the Categories: list box. Select the required action from the Actions: list box. Click on the Next button. Select the appropriate option. Click on the Next button. Designate text or a graphic for the button. Click on the Next button. Enter a name for the button. Click on the Finish button.

Page 120 WWP Learning and Development Ltd

OPENING A SWITCHBOARD AUTOMATICALLY 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 109) 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 achieved using Access options.

To automatically show a switchboard form upon opening a database file, click the Office button. Click the Access Options... button. Select Current Database in the pane at the left. Click the Display Form drop-down list in the Application Options section. Select the name of the switchboard form. In the Navigation section below, deselect the Display Navigation Pane check box. Click OK.

WWP Learning and Development Ltd Page 121

EXERCISE - USING SWITCHBOARDS

1. Open Train36x.

2. Create a blank form. Change the view to Design view.

3. Insert the image, Computer.wmf, at the right of the form.

4. Change the Format properties of the form as shown in the following table:

Property Setting Default View Single Form Scroll Bars Neither Record Selectors No Navigation Buttons No Auto Resize Yes Auto Center Yes

5. Close the property sheet.

6. Disable the Control Wizards, if necessary. Add a command button to the upper left corner of the form.

7. Open the property sheet for the command button.

8. 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.

9. Close the property sheet.

10. Create another command button on the form approximately 1.5cm (1/2”) below the Open Forms button. Open the property sheet for the command button.

11. On the Event page, set the On Click property to run the Customer Macros.Print the Report macro. On the Format page, enter the text Print Report as the caption.

12. Close the property sheet.

13. Enable the Control Wizards. Add another command button to the form approximately 1.5cm (1/2”) below the Print Report button.

14. In the Command Button Wizard, select the Form Operations category and the Close Form action. Display text on the button that reads Close Switchboard. Name the button Closes Switchboard.

15. Align the buttons, if necessary. Close and save the form.

16. Specify in Access Options for the Switchboard to display upon opening the database file.

17. Close and reopen Train36x. Notice that the switchboard opens.

Page 122 WWP Learning and Development Ltd

18. Test the buttons on the switchboard. Close any open windows, as necessary. 19. Close the database file.

WWP Learning and Development Ltd Page 123

15 CUSTOMISING THE QUICK ACCESS TOOLBAR

INTRODUCTION When a Microsoft Office program starts, the Quick Access Toolbar appears at the top of the window, unless the settings have been changed.

The Quick Access Toolbar contains only the most popular buttons though you can modify this. The Quick Access Toolbar can be moved below the ribbons and, if necessary, commands can be inserted in the Toolbar. You can also assign macros to buttons on the Toolbar, as well as removing, or adding, buttons and groups.

Where necessary, you can minimise the ribbon, placing the commands a user will need on the Quick Access Toolbar.

In this lesson, you will learn how to: Move the Quick Access

Toolbar

Add or remove items from the Quick Access Toolbar

Customise the Quick Access Toolbar

Assign a macro to the Quick Access Toolbar

To move the Quick Access Toolbar, click on the pull down beside the Quick Access Toolbar. In the list, click on the Show Below the Ribbon item. The Quick Access Toolbar will be displayed below the ribbon.

Page 124 WWP Learning and Development Ltd

To add or remove items from the Quick Access Toolbar, click on the Customise Quick Access Toolbar list arrow. Click to place, or remove, the check for that item. To add a ribbon button or group to the Toolbar, use the right mouse button to click on the button/group on the Ribbon. Click on the Add to Quick Access Toolbar item. To remove a button or group, use the right mouse button to click on the button/group on the Quick Access Toolbar. Click on the Remove from Quick Access Toolbar item.

WWP Learning and Development Ltd Page 125

To customise the Quick Access Toolbar, click on the Customize Quick Access Toolbar list arrow. Click on the list arrow. Click on the More Commands… item. Click on the Choose commands from: list arrow. Click on the item you require. If necessary, click on the Customize Quick Access Toolbar list arrow and click on For all documents (default). Click on the command you want to add from the left column. Click on the Add button. Click on the Move Up and Move down arrow buttons to arrange the commands in the order you want. Click on the OK button.

Page 126 WWP Learning and Development Ltd

ASSIGNING A MACRO TO A 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.

To assign a macro to a toolbar, click on the Customize Quick Access Toolbar list arrow. Click on the More Commands… item. Click on the Choose command from: list arrow. In the list, click on Macros. Click on the macro you intend to add from the left column. Click on the Add button. Click on the Modify… button. In the Modify Button box, type a name in the Display name: box. Click on the icon you want to use for the button. Click on the OK button. Click on the OK button to close the Access Options. The button is displayed on the Quick Access Toolbar.

WWP Learning and Development Ltd Page 127

EXERCISE - CUSTOMISING THE QUICK ACCESS TOOLBAR

1. Open Train37x.

2. Close the switchboard.

3. Move the Quick Access Toolbar to a location below the Ribbon.

4. Add the Query Design button to the Quick Access toolbar.

5. Assign the Open Invoice/Payment Forms macro to the Quick Access Toolbar.

6. Run the macro from the Quick Access Toolbar.

7. Remove the Query Design button from the Quick Access Toolbar.

8. Remove the macro button from the Quick Access Toolbar.

9. Close any open windows. 10. Close the database file.

WWP Learning and Development Ltd Page 129

WWP Learning and Development Ltd Page 131

APPENDIX A - USING ACCESS AND THE INTERNET

INTRODUCTION Access 2007 allows you to save tables, forms, and reports as Web documents and the databases can contain links to internet resources, connection to online Help being one useful link.

The Web is an enormous arrangement of documents connected together with hypertext links or hyperlinks for short. Using hyperlinks you can retrieve another Web document, called the target of the link. The main advantage of hyperlinks is that you do not have to know where or how the target is stored. The target is identified by its URL or Uniform Resource Locator, which uniquely identifies the location of the target on the internet.

Web pages are created in a language called HTML, Hypertext Markup Language, a multi-platform which any operating system can use to access a Web page.

WORKING WITH HYPERLINKS Access 2007 supports the use of hypertext within the application. Hypertext, or hyperlinks, are strings of text that declare an address or a path to a document. Hypertext is active in that, if you click it, your PC and/or modem lead you to the document. Hyperlinks provide an electronic path to documents in much the same way as your home address provides a path for the mail you receive.

Hyperlinks can be a URL address or a UNC address. The URL (Uniform Resource Locator) is the address of a resource, or file, available on the Internet or your intranet. The URL contains the protocol of the resource (e.g. http:// or ftp://), the domain name for the resource, and the hierarchical name for the file (address). Domain extensions identify the source; .com for companies, .org for organizations, .gov for government, and .edu for educational institutions.

CREATING A HYPERLINK FIELD You can add hyperlinks to tables in Design view by adding a field name and identifying it as a hyperlink data type. You can then add hyperlinks to the appropriate column in Datasheet view, allowing you to jump to objects in the same database, in another database, in other Microsoft office documents, on the internet, or on an intranet.

In this lesson, you will learn how to: Work with hyperlinks

Create a hyperlink field

Insert a hyperlink

Edit a hyperlink

Delete a hyperlink field

Import a HTML file

Export to a HTML file

Use SharePoint

Page 132 WWP Learning and Development Ltd

INSERTING A HYPERLINK You can insert a hyperlink into a field in a table or form. However, the field data type must be designated as Hyperlink. The default settings display a new hyperlink in blue underlined text and a followed hyperlink (one that has been used) in purple underlined text.

When you click the label, the hyperlink path is followed to the specified location. The document at the end of the path can be a web page for company headquarters anywhere in the world, another form or report in the current database, or anywhere in between. For example, in the header of an Annual Sales Report, you can insert hyperlink labels that, when activated, open related reports, such as a Quarterly Sales Report for that year.

Hyperlink labels in forms or reports must contain a viable path, but the path itself does not need to be displayed on the label. As with hyperlink fields, you can display a label with descriptive text rather than the actual path.

When you point to a hyperlink, the mouse pointer changes into a hand pointing upward, signifying that one mouse click activates the hyperlink.

To create a Hyperlink field in a table, first display the table in Design view. Create a new field in which you want to store the hyperlink. In the Data Type column, click on the list arrow. Click on Hyperlink. Save, and close, the table.

To insert a hyperlink to a file or Web page, first open the object containing the hyperlink field. In Design view, click on the Design tab to use the Insert Hyperlink button. Alternatively, in datasheet, or form view, you can use the right mouse button to click on a hyperlink field and choose Hyperlink from the shortcut menu. Click on the Edit Hyperlink… button Locate and specify the linked document in the Edit Hyperlink dialog box. Click on the OK button.

WWP Learning and Development Ltd Page 133

EDITING A HYPERLINK You may occasionally have to edit your hyperlinks. Changes in web addresses are common, and any file location changes on your PC or server need to be reflected with an updated hyperlink. You can edit the hyperlink text or replace it with a new location.

Using the right mouse button to click in form or datasheet view allows you to select Edit Hyperlink… from the shortcut menu. You can then modify the hyperlink accordingly.

DELETING A HYPERLINK FIELD If a hyperlink becomes invalid, or is no longer of any use, it can be deleted. As with editing a hyperlink, you cannot simply double-click a hyperlink to select it.

You can also delete a hyperlink by selecting it and pressing the [Delete] key.

To delete a hyperlink, first open the required table in datasheet view or form in Design view. Use the right mouse button to click on the hyperlink you intend to delete. In the shortcut menu, click on the Hyperlink command. Click on Remove Hyperlink.

Page 134 WWP Learning and Development Ltd

EXPORTING DATABASE OBJECTS TO HTML In Access 2007, 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.

To export to a HTML file, first select the table, query, form, or report you wish to export. Click on the External Data tab. In the Export group, click on the More button. Click on HTML document. In the Export - HTML Document dialog box, use the Browse… button to locate and specify the file destination. Specify which export options you want. Click on the OK button. Specify the output options required. Click on the OK button. Choose whether or not to save the export steps and click on the Close button.

WWP Learning and Development Ltd Page 135

IMPORTING OR LINKING TO A HTML FILE You can import HTML files into Access tables. Access uses the Import HTML Wizard for you to specify how you intend to import the data into your database.

To import or Link to a HTML file, first open he database you wish to import to. Click on the External Data tab. In the Import group, click on the More button. Click on HTML Document. Specify the name and location of the file. Click on the OK button. Click on the option you require for importing the data from: Import the source data into a new table in the current database Append a copy of the records to the table Link to the data source by creating a linked table. Click on the OK button. Use the Import HTML Wizard pages to specify how you want to import the data. After naming the new table, click on the Finish button. If necessary, click to save the Import steps. Click on the Close button. The HTML file is displayed as a table

Page 136 WWP Learning and Development Ltd

USING SHAREPOINT 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.

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.

To create a table using a SharePoint List, first click on the Create tab. In the Tables group, click on the SharePoint Lists button. Click on the SharePoint list template you want. Enter a SharePoint side address or select an existing one. Enter a name and description. To open the list, place a check in the Open the list when finished check box. Click on the OK button.

WWP Learning and Development Ltd Page 137

EXERCISE - USING ACCESS AND THE INTERNET

1. Open Train33x.

2. Create a field called Link with a Hyperlink data type in the Sales table.

3. View the Sales table and enter into the first record a hyperlink to: www.abbott.net

4. Click the hyperlink text to display web page. Close the browser.

5. Edit the hyperlink so that it opens the Abbott Contract Word document (Hint: Right click the data in the table and select the Hyperlink menu).

6. Test the hyperlink to display the Word document. Close Word.

7. Delete the hyperlink. 8. Import the reps.html file. View the new table and close it. 9. Export the Trainer table as a html document. Choose to view

the document after export. After viewing the html document, close the Explorer.

10. Close the database.

Page 138 WWP Learning and Development Ltd

APPENDIX B – ADVANCED ACCESS SECURITY

INTRODUCTION If you need to validate the authenticity of a database, you can package the database in a file and add a digital signature as proof of authentication.

Additional security options can be set in the Trust Center which is in Access Options.

CREATING A DIGITAL SIGNATURE Once you have constructed your database, you can add an electronic stamp of authentication on the file, a digital signature. Applying a digital signature to a component is known as code-signing. You apply your signature to your database so other certified users will know it is safe to use.

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 on of your own. Such a certificate would be known as a self-signed certificate.

In this lesson, you will learn how to: Use digital certificates

Create digital certificates

Use the Trust Center

Lock a database

Lock database records

To create a self-signed certificate, click on the Start button. Point to All Programs. Click on Microsoft Office. Click on Microsoft Tools. Click on Digital Certificate for VBA Projects. Enter a name. Click on the OK button. In the Self Cert Success box, click on the OK button.

WWP Learning and Development Ltd Page 139

ADDING A DIGITAL SIGNATURE TO A DATABASE If you need to add a digital signature to a document with a macro, you do it using the Visual Basic Editor. Should you open a document containing a signed macro with a problem the macro is disabled by default and the Message Bar is displayed indicating the possible problem. Clicking on Options in the Message Bar enables you to view more information about the problem.

For further details, clicking on Show Signature Details allow you to see the certificate and publisher information. If there is a problem with the digital signature, such as date expired, or the document has been altered, the certificate information contains a red X.

DIGITALLY SIGNING AND PACKAGING A DATABASE The Package and Sign command in the Office menu allows you to package, digitally sign, and distribute an Access database. The database is saved in a different format (.accdc). Access signs the package and then stores the digitally signed package where you wish to locate it. Other users can extract the database from the package and work directly in the database.

To sign a database, first open the required database. Click on the Database Tools tab. In the Macro group, click on the Visual Basic button. In the Project window, click on the database. Click on the Tools menu. Click on Digital Signature… In the Digital Signature dialog box, click on the Choose… button. Select your certificate. Click on the OK button. In the Digital Signature box, click on the OK button. Close the Visual Basic window.

Page 140 WWP Learning and Development Ltd

To create a signed package, first open the database you want to package and sign. Click on the Office button. In the Office menu, move the mouse cursor to Publish. Click on Package and Sign. Select the digital certificate you want to use. Click on the OK button. Specify the location for the database package. Enter a name for the database package. Click on the Create button.

To extract and use a signed database, click on the Office button. Click on Open. In the Files of type: list, select Microsoft Office Access Signed Packages. Locate and specify the file you want. Choose one of the options if you have not chosen to trust the digital certificate. In the Extract dialog box, select the location for the database. Enter a name for the database. Click on the OK button.

WWP Learning and Development Ltd Page 141

USING THE TRUST CENTER 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.

LOCKING A DATABASE In the Database Tools group is the Make ACCDE button which allows you to lock a file and prevent users from viewing or modifying any VBA code, and from making any changes to reports or forms.

Using the 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.

To view the Trust Center, click on the Office button.

Click on the Access Options button.

In the left pane, click on Trust Center.

You can choose from the link options to view:

privacy practices, Improvement Program, the Windows Security Center.

Click on the Trust Center Settings… button.

You can set, or change, options concerning:

Trusted Publishers Trusted Locations Add-ins Macro Settings Message Bar Privacy Options.

When completed, click on the OK button.

Click on the OK button to leave the Access Options.

Page 142 WWP Learning and Development Ltd

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.

LOCKING DATABASE RECORDS 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, ensuring 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.

To create a locked database, first open the file you want to lock. Click on the Database Tools tab. In the Database Tools group, click on the Make ACCDE button. In the Save As dialog box, specify the location and name for the file. Click on the Save button.

To set record locking, first open the required database. Click on the Office button. Click on the Access Options button. Click on Advanced in the left pane. In the right pane, choose the Shared or Exclusive option as required. Click the Default Record Locking to be one of

No locks All records Edited record.

Click on the Open databases by using record-level locking check box. Click on the OK button.

WWP Learning and Development Ltd Page 143

EXERCISE - USING ACCESS SECURITY

1. Create a self-signed certificate.

2. Open Train33x.

3. Add your digital signature to the database. Save the file in the student folder as mysignedfile.

4. Close the database.

5. Extract, and open, the mysignedfile. In the Security Notice, use the Open option. Change the file name to extracted.

6. Lock the extracted file, naming it as locked extracted. Close the file.

7. Open the file locked extracted and attempt to change the design of the Trainer form. Close the database.

WWP Learning and Development Ltd Page 145

Index

A

ActiveX controls attaching ............................................... 56 using ...................................................... 55

C

Calculated controls creating ................................................. 62

Charts adding data labels ............................... 78 changing the type ................................ 75 Chart Wizard ........................................ 73

Combo boxes creating ................................................. 50

Command buttons adding to switchboard ...................... 119 creating ............................................... 105

Controls ActiveX controls .................................. 55 adding logic .......................................... 54 creating calculated ............................... 62 using the Combo Box tool .................. 51 using the Option Group tool ............. 53

Crosstab queries creating ................................................. 25

D

Data exporting ............................................... 11 importing ................................................ 9 linking to a table .................................. 10

Data formats ............................................. 12 Database objects

exporting ............................................... 11 importing ................................................ 9

Databases backing up ............................................ 19 compacting ........................................... 18

Date control inserting ................................................ 67

E

Exporting data ........................................................ 11

F

Fields

Yes/No ................................................. 54 Find Duplicates Query Wizard

using ...................................................... 26 Find Unmatched Query Wizard

using ...................................................... 28 Footer

adding to a form .................................. 40 adding to a report ................................ 61

Form Footer .............................................. 38 Form Header ............................................ 38 Forms

adding a form header and footer ...... 40 adding logic controls .......................... 54 creating a combo box .......................... 50 creating a list box ................................. 51 creating an option group .................... 52 creating blank ...................................... 41 sections .................................................. 38 setting the tab order automatically ... 39 setting the tab order manually .......... 39 using in Design view .......................... 38

G

Group footers creating ................................................. 64

Group headers creating ................................................. 64

Group macros creating ............................................... 107

Grouping report data ............................................ 63

H

Header adding to a form .................................. 40 adding to a report ................................ 61

Hyperlinks creating fields ..................................... 131 deleting fields .................................... 133 editing fields ...................................... 133 inserting fields ................................... 132 working with ..................................... 131

Hypertext working with ..................................... 131

I

Indexes creating a multiple field ..................... 89

Page 146 WWP Learning and Development Ltd

creating a multiple field primary key91 creating a single field .......................... 88 deleting ................................................. 90 viewing ................................................. 87

J

Join lines deleting ................................................. 35

L

List boxes creating ................................................. 51

M

Macros adding a condition ............................ 106 assigning an argument to an action .. 95 assigning to a control ........................ 104 creating Autoexec .............................. 109 creating group .................................... 107 creating using the Macro Builder ...... 99 editing existing .................................... 98 running ................................................. 97 running using the Tools menu .......... 98 saving .................................................... 95 using single step mode for testing .... 96 working with ........................................ 93

Microsoft Graph adding chart data labels ..................... 78 changing the chart type ...................... 75 formatting the chart title..................... 77

N

Name AutoCorrect using ...................................................... 19

P

Page breaks inserting ................................................ 67

Page Footer ......................................... 38, 61 Page Header ....................................... 38, 61 Performance Analyzer .............................. 5 PivotChart

creating a view ..................................... 41 PivotTable

creating a view ..................................... 41 Primary key

creating a multiple field ..................... 91 Properties

using .................................................... 103

R

Referential integrity setting .................................................... 33

Relationships creating between tables ...................... 32 deleting join lines ................................ 35 one-to-many ......................................... 32 one-to-one ............................................. 32 setting referential integrity ................ 33 using related tables ............................. 31 window ................................................. 32

Reports adding headers and footers ............... 61 creating a calculated control .............. 62 creating a running summary ............. 66 creating blank ...................................... 69 creating without a wizard .................. 69 grouping data ...................................... 63 inserting a date control ....................... 67 inserting a page break......................... 67 inserting a time control ....................... 67 sections .................................................. 61 using in Design view .......................... 61

Running summary creating ................................................. 66

S

Subdatasheets viewing ................................................. 34

Subforms creating ................................................. 81 displaying a total ................................. 84 displaying in Datasheet view ......... 83 editing the layout ................................ 83 working with ....................................... 81

Subreports creating ................................................. 81 displaying a total ................................. 84 editing the layout ................................ 83 working with ....................................... 81

Switchboards adding a command button ....... 119, 120 creating ............................................... 118 opening ............................................... 117 using .................................................... 117

T

Tab order setting automatically........................... 39 setting manually .................................. 39

WWP Learning and Development Ltd Page 147

Table Analyzer Wizard ............................. 3 Tables

analyzing ............................................ 3, 5 deleting join lines ................................ 35 joining ................................................... 32 linking ................................................... 10

linking data .......................................... 10 related ................................................... 31 splitting ................................................... 3 viewing subdatasheets ....................... 34

Time control inserting ................................................ 67

WWP Learning and Development Ltd Page 149