ECDL Module 5 Notes ECDL Module 5 Notes Module 5 – Microsoft Access 5.1 Understanding Databases 5.1.1 Key Concepts 5.1.1.1 Understand what a database is. A database is a structured collection of related information. In normal daily life we make frequent use of databases, and probably don’t realize it. Here are a number of simple examples: - The telephone directory - Personal address book - Filing cabinet Relational Database on the other side is:Able to store and manipulate data across multiple tables unlike a single table database By utilising multiple tables, a relational database reduces unnecessary duplication of data. For example, when using a large database to store customer information including addresses, it is likely many individuals will live in the same street and share other common parts of the address. Rather than storing the same street name, country, state, etc, over and over, this information can be stored in a separate table. As each new customer is added to the database, only the unique house number needs to be recorded 5.1.1.2 Understand the difference between data and information. Data is the information entered into tables within the database. Databases are used daily by large corporations, small businesses and individuals, often without people realizing they are using a database While information is all the data put together. Data:Facts, statistics used for reference and analysis Numbers, characters, symbols, images etc, which can be processed by a computer Data must be interpreted, by a human or machine, to derive a meaning Information:Information is interpreted data Data has been processed to produce meaning © TCTC Page 2 ECDL Module 5 Notes 5.1.1.3 Understand how a database is organized in terms of tables, records and fields. What is a table? Tables are used to store the data in a structured and organised format. Tables are similar to those of Word and Excel, in that the way contains rows (records) and columns (fields). What is a record (row)? A record applies to data entered into a single row of a table. All data in that row would be long to an individual or item. A record would normally include a unique ID number, Name, Description, plus other relevant information. With each new record, a new row is created. What is a field (column)? Each column (previously known as a ‘field’) is used to define what specific information is to be entered into that particular column. A column titled ‘Street’ for example would signify this to be the point in a record to enter in the Street name when creating each new record. © TCTC Page 3 ECDL Module 5 Notes 5.1.1.4 Know some of the common uses of large-scale databases like: airline booking systems, government records, bank account records, hospital patient details. Airline booking systems: These systems maintain a database of all the seats on all the available flight, allowing passengers to be quickly b ooked onto fights to their destination. Government records: Governments all over to world rely on multiple large databases in order to function. Tax records, criminal records and social security all require sophisticated database systems. Bank account records: Banks require extremely reliable databases in order to keep track of all their customer account & log transactions. Hospital patient details: Medical records are being moved onto a database system. This system should allow your medical history to be instantly available wherever you require treatment. 5.1.2 Database Organization 5.1.2.1 Understand that each table in a database should contain data related to a single subject type. A database can have many tables. A table should only contain records related to a particular subject. For example you may have a table called customers containing information about your customers with a separate table called orders. You can then link the tables by creating a relationship, connecting each customer with their associated orders. 5.1.2.2 Understand that each field in a table should contain only one element of data. Each field should contain the smallest data element. For instance, if you are storing a person’s name, use one field for the first name and another field for the second name. This means that at a later date you could manipulate the data to sort by the second name. For the same reason split the details of an address into as many smaller parts as possible so that later you could search by state/region , by post code/zip code or even by country if you are maintaining an international list. © TCTC Page 4 ECDL Module 5 Notes 5.1.2.3 Understand that field content is associated with an appropriate data type like: text, number, date/time, yes/no and 5.1.2.4 Understand that fields have associated field properties like: field size, format, default value. Data types define what type of data will be entered into each ‘field’ (column) in a table. If for example the date ‘12June2007’ or Price 1.59 is entered into a field, which by default is set as ‘Text’ the input characters will remain unchanged. If however the data type is set to a currency or date ‘Data Type’, numeric data entered will automatically format to the appropriate currency or data/time format. There are a number of specific reasons for selecting the correct data types when creating Tables within a database. Setting a ‘Date’ Data Type for example will format and store all entries in the manner configured. This in turn means that queries created to locate information according to a ‘Date’ criteria will have consistent data to work with. In the same way, Numeric data must be of a numeric type, otherwise query searches, reports and calculations will fail to provide the desired information. NOTE: Field Properties must also be configured to format the appropriate currency symbol, date format and to limit the data entry to specific characters, symbols and spacing © TCTC Page 5 ECDL Module 5 Notes 5.1.2.5 Understand what a primary key is. A primary key is used as a unique identifier for each record in a database table and is essential when working with relational tables. To be effective, a primary key cannot have duplicate entries and must be set on a field generating a unique identifier. When creating a new table Access automatically adds the ID field with an AutoNumber data type. By default the ID field is also the primary key. Other fields suitable to be set as a primary key are for example passport, social security and driving licence numbers, military identification, tax, workplace or personal identification numbers, unique to each individual. NOTE: A primary key field can never be empty. 5.1.2.6 Understand what an index is. Understand how it allows for faster data access. Access uses indexes much like a Table of Content to help locate and sort information quickly. An index stores the location of records based on the field or fields that you choose to index. After Access obtains the location from the index, it can then retrieve the data by moving directly to the correct location. As mentioned earlier, by default, Access set the Primary key as the Index within a table, however indexing can be set on other fields, especially fields used frequently in searches. NOTE: Although indexing may speed up searches, it can also slow the process of updating data within tables. Also, you cannot index OLE objects or attachment fields. As a guide, consider indexing a field if all of the following conditions are met: - The field's data type is Text, Memo, Number, Date/Time, AutoNumber, Currency, Yes/No or Hyperlink. - You anticipate searching for values stored in the field. - You anticipate sorting values in the field. You anticipate storing many different values in the field. If many of the values in the field are the same, the index might not significantly speed up queries. Indexing can also be set for multiple fields. If you are likely to perform searches on two or more fields within a single query, it makes sense to create a multiple-field index on both fields. NOTE: You can include up to 10 and set the order of fields in a multiple-field index. © TCTC Page 6 ECDL Module 5 Notes When you sort a table using a multiple-field index, Access first sorts by the first field defined for the index. If there are records with duplicate values in the first field, Access then sorts using the second field defined for the multiple-field index. Before creating an index, decide whether you want to create a single-field index or a multiple-field index. You create an index on a single field by setting the Indexed property. The following table lists the possible settings for the Indexed property. NOTE: By setting the Index property to No Duplicates, Access prevents any new value which matches an existing value from being entered into the field. For example, indexing the ID field in a table and setting it to Yes (No Duplicates) prevents duplicate numbers being entered and therefore the values in the field remain unique. 5.1.3 Relationships 5.1.3.1 Understand that the main purpose of relating tables in a database is to minimize duplication of data. Good database design suggests data is organised across multiple tables, as to store data in one single table would; 1) Result in vast amounts of duplicated data and 2) Quickly become unmanageable. Relationships are used to create a link between two or more tables within a database. When a link is established and with the use of other objects within the database, data can be entered into or viewed from one or more tables at the same time, without the need to close one table and open another. The most common relationships between tables are: One-Many Many-Many One-One © TCTC Page 7 ECDL Module 5 Notes 5.1.3.2 Understand that a relationship is built by matching a unique field in one table with a field in another table. A relationship is built by matching a unique field within one table with a field within another table. One-to-many relationship Consider a Parts sales database that includes a Customers table and an Orders table. A customer can place any number of orders. It follows that for any customer represented in the Customers table, there can be many orders represented in the Orders table. The relationship between the Customers table and the Orders table is therefore a one-to-many relationship. To establish a one-to-many relationship between tables, it is necessary to take the Primary Key (normally the ID field) of the ‘one’ side of the relationship, (in this case the Customer table) and add it as an additional field within the ‘many’ side (Orders) table. TIP: This requires you to add a new (Customers ID) field to the Orders table and set the data type. As the AutoNumber field can only be used once in a table, the Number data type is used. Notice the Customer ID field is included in the Orders table, shown in the following image. NOTE: When using the name of a primary key field to create a field in another table and thereby a link, the new field is often referred to as a Foreign key. Many-to-many relationship Consider the relationship between a Parts (Product) table and an Orders table. A single order might include more than one product. On the other hand, a single product can appear on many orders. For each record in the Orders table therefore, there can be many records in the Products table. In addition, for each record in the Parts table, there can be many records in the Orders table. This type of relationship is called a many-to-many relationship because, for any product, there can be many orders and, for any order, there can be many products. A many-to-many relationship, is actually achieved by creating two one-to-many relationships, using a third table, often referred to as a Junction. The Primary key from © TCTC Page 8 ECDL Module 5 Notes both the Parts and Orders tables are added to the third table (junction) thereby effectively creating two one-to-many relationships. NOTE: In many circles, a many-to-many relationship between your tables is not considered ideal and consideration should be given to the design, possibly breaking data across additional tables to avoid the necessity for many-to-many relationships. One-to-one relationships In a one-to-one relationship, each record in the first table can have only one matching record in the second table, and each record in the second table can have only one matching record in the first table. This type of relationship is not common because, most often, the information related in this way is stored in the same table. One example of a one-to-one relationship might be to transfer sensitive data to another table and isolate it for security reasons. NOTE: Both tables must share a common field but not necessarily a Primary key field. 5.1.3.3 Understand the importance of maintaining the integrity of relationships between tables. Good database design suggests dividing information into many subject-based tables to minimize data redundancy. Relationships are then used to bring the data back together by placing common fields into related tables. To bring data back together, Access uses the value in the "many" table to look upthe corresponding value in the "one" table. Suppose you have a one-to-many relationship between Parts and Orders and you want to delete a Part (Item). If the Part you want to delete has orders in the Orders table, those orders will become "orphans" when you delete the Parts record. The orders will still contain a Part ID, but the record (Parent) that it references no longer exists. Referential integrity is designed to prevent this situation occurring and keep references in sync so that this kind of situation never occurs. Referential integrity by default is not enabled and therefore has to be enabled either during the creation of relationships or when editing relationships. When enabled, Access will reject any operation that violates referential integrity for that particular relationship. Access rejects updates that change the target of a reference or deletions that remove the target of a reference. In other words, if you attempt to delete an individual part from © TCTC Page 9 ECDL Module 5 Notes the Parts table that has been referenced in the Orders table (included in an order), Access will prevent this from happening. 5.1.4 Operation 5.1.4.1 Know that professional databases are designed and created by database specialists. These are highly skilled database professionals with an in-depth knowledge of exactly how the database works, including its overall function and details programming. 5.1.4.2 Know that data entry, data maintenance and information retrieval are carried out by users. The users are responsible for routine, day to day data entry, data maintenance and information retrieval. 5.1.4.3 Know that a database administrator provides access to specific data for appropriate users and 5.1.4.4 Know that the database administrator is responsible for recovery of a database after a crash or major errors This group administers the day to day operation of the database and make sure that the data is kept secure. These provide technical backup to users of the database. They provide access to specific data for appropriate users. In the event of a computer crash the database administrator will be responsible for restoring normal computer operations. © TCTC Page 10 ECDL Module 5 Notes 5.2 Using the Application 5.2.1 Working with Databases 5.2.1.1 Open, close a database application Open Access Click on the Start button (bottom left of screen) and then select All Programs. Scroll up until you locate the Microsoft Office folder button and click to select. Finally click on the Microsoft Office Access 2007 icon. © TCTC Page 11 ECDL Module 5 Notes Closing Access To close the Access program, click on the Close icon at the top-right corner of the program window. This icon contains an X shape. TIP: The keyboard shortcut for closing Access is Alt+F4. 5.2.1.2 Open, close a database. Open the Access Program. Click on the Office Button and from the menu displayed click on the Open command. This will display the Open dialog box. By default the contents of the Documents folder will be displayed You should see a folder displayed containing the Access 2007 foundation sample files. Double click on this sample folder to display the contents of the folder. Select a database file called Sample and double click on it to open it. © TCTC Page 12 ECDL Module 5 Notes The database will look like this when opened. If you look carefully at the screen, you will see a warning dialog message displayed. © TCTC Page 13 ECDL Module 5 Notes 5.2.1.3 Create a new database and save to a location on a drive. Creating a new blank database Click on the Microsoft Button Click on New Select the Blank Database icon. You need to give the new database a name and also set a folder location to store it in. In this case we previous set the default folder to point to our Access 2007 samples folder, and if you look carefully at the right side of the screen you will notice that this default folder has been used. NOTE: If you had wanted to create a new database in a different folder, then you would have clicked on the small folder icon to the right of the File Name section and navigated to the desired folder. In this case however we will be use the default folder location. Replace the default database file name with the nameTCTC, and then click on the Create button. © TCTC Page 14 ECDL Module 5 Notes NOTE: Access 2007 saves database files with an .accdb file name extension, unlike earlier versions of Access which used an .mdb file name extension. The Access window opens and displays a new table, as this is the next step to creating the new database. Until one or more tables have been created, given fields and properties set, Access can do little at this stage. This view of the table, is referred to as the Datasheet View, which means the Object, in this case the Table is displayed in its normal (default) view. The Design View is used to configure the properties of an object. Think of the Design View as looking behind the Object at its inner workings. Saving a table 5.2.1.4 Display, hide built-in toolbars. Restore, minimize the ribbon Display toolbars Right click on an existing toolbar and click on Customize quick Access Toolbar Choose a tool Click Add © TCTC Page 15 ECDL Module 5 Notes And Remove toolbars Right click on an existing toolbar and click on Customize quick Access Toolbar Choose a tool Click Remove Minimize the ribbon Click Customize Quick Access Toolbar . In the list, click Minimize the Ribbon. Restore the Ribbon Click Customize Quick Access Toolbar . In the list, click Minimize the Ribbon. © TCTC Page 16 ECDL Module 5 Notes 5.2.1.5 Use available Help functions. As with all Microsoft applications, Help is always available. In the upper righthand corner of the application window, is a Help button. When clicked, it will open the Access Help window. Alternatively, pressing the F1 function key, normally located in the top row of the keyboard, will also activate the help window. From the help window, you will be able to select and click on the topics listed or type in a word or words into the Search box and have Access Help search the files for all matching help topics. As an example of using Help, type in the subject you need help with and then press the Enter key on the keyboard or click on the Search button. © TCTC Page 17 ECDL Module 5 Notes 5.2.2 Common Tasks 5.2.2.1 Open, save and close a table, query, form, report. Saving a table Before a table can be used to store information, fields must be added to a table, named, given the correct Data Type and formatted appropriately. Fields are used to separate and organise data into specific fields (columns), for example a First Name field would store the first name for every individual record entered, as would Surname, Birth Date fields, etc. NOTE: A software issue has affects the start number in the ID field. For example, if 5 fields are added to a new table, rather than the ID number starting a with ‘1’, the first record will actually be record ‘5’. This issue can be avoided easily by saving the table before any fields are added. Click on the Save button on the Quick Access Toolbar or press the Ctrl+S keys to save the table The Save As dialog box is displayed with a default name. Replace the default table name Click on the OK button © TCTC Page 18 ECDL Module 5 Notes 5.2.2.2 Switch between view modes in a table, query, form, report Using Datasheet View Every object (Table, Form, Query, Report, etc) in an Access database will have at least two main views, Datasheet View and Design View. Datasheet View displays the object as it would be seen in daily use, its working mode so to speak. Using Design View Design View displays the workings behind the object, as seen by the database designer. The efficiency of the database and the way it handles data input /output are controlled by the properties configured in Design View. NOTE: The View button image displays the opposite view button to the current view, i.e. if in Datasheet View, the Design View button is displayed. To change from Datasheet View to Design View click on the View button (displayed within the Views section of the Datasheet tab 5.2.2.3 Delete a table, query, form, report. To delete an object, i.e. a table from a database, that object must be closed so first close any open tables In the Navigation Pane, right click on Copy of Parts:Table and from the popup list displayed select the Delete command from the list. Access displays the following warning. Click on the Yes button to confirm deletion. The table is deleted from the database and removed from the Navigation Pane © TCTC Page 19 ECDL Module 5 Notes 5.2.2.4 Navigate between records in a table, query, form. The record navigation bar is located and will only visible from the bottom of the object window when, for example, a table is open to view As tables grow, navigating records becomes more difficult, therefore Access has the record navigation bar to help locate records more easily. There are 5 options for navigating existing records and one for creating a new record. The options for navigating are similar in fashion to the controls in a CD/DVD player. See below. First Previous Specific Next Last To use the specific record option, click within the box and enter a record number, then press the Enter key. The last option provides a quick way to create a new record without having to scroll to the last record first. 5.2.2.5 Sort records in a table, form, query output in ascending, descending numeric, alphabetic order. To sort a single field, first select the field you want to sort. Click on the Product Name field name to highlight the column. © TCTC Page 20 ECDL Module 5 Notes Within the Home tab, in the Sort & Filter group, click on the A-Z button. NOTE: Unlike working with filters, a sort will remain active until removed, even when a table is closed and reopened (the table must be saved prior to closing). You can sort in numeric order. To see this click within the Quantity column. Then click on the Ascending button. The table is now sorted in ascending numeric order. Clicking on the Descending button will reorder in descending numeric order © TCTC Page 21 ECDL Module 5 Notes To remove a sort, click on the Clear All Sorts button in the Sort & Filter group. The table returns to the default sort order. To sort on two or more fields, the steps are similar to those used when sorting a single field however the order in which you set the sort will have an impact on the outcome. In the table below, the Sales Account Manager and the Category fields are side by side, with the Sales Account Manager Field to the left of the Category field. This positioning is relevant when using a sort on multiple fields in a table, as the left most field in the select group of fields, takes priority over the fields to the right. A sort is needed to organise the Sales Account Managers into alphabetical order first, then sort the Category field so that categories within that field are alphabetical according to each Sales Account Manager, as seen in the image below. 5.3 Tables 5.3.1 Records 5.3.1.1 Add, delete records in a table. On the left side of the table there is a small * symbol. This symbol represents the record (row) currently selected. As more records are entered into the table or as you navigate through the table, this symbol will provide a confirmation of the exact row you or your pointer is in. To the right of the * symbol, New is displayed just below the ID field name, signifying this row represents a new record. Data cannot be typed into this column, as by default this is an ID column with an AutoNumber Data Type. © TCTC Page 22 ECDL Module 5 Notes NOTE: The AutoNumber Data Type automatically generates a unique, sequential number for each new record entered so data entry into this field is restricted. Deleting a Record Occasionally you may need to remove a record from a table. Move the pointer to the column, left of the ID field. When the pointer changes to a right pointing arrow, click to highlight the whole row (record). With the pointer anywhere within the highlighted area, click using the right mouse button to activate the shortcut menu. Click on the Delete Record option. A warning is displayed. NOTE: Undo is not available when deleting records, therefore any deletions will be committed. Click on the Yes button to confirm the deletion. © TCTC Page 23 ECDL Module 5 Notes Deleting multiple records If a group of records needs to be deleted, the process is similar to deleting a single record. The only difference is in selecting the records. Move the pointer left to the row selection column. Locate the first record in the group and with the right pointing arrow displayed, click and drag down to create a highlighted block of records. Delete all records in the same way as shown in the previous section describing how to delete a single record. 5.3.1.2 Add, modify, delete data in a record. To add data simply do on the box you need to add data and star typing. For modifying data the same click on the box that you need to change place your cursor before or after that word, and type what you need. To delete data select the box that you need to delete and press delete from your keyboard 5.3.2 Design 5.3.2.1 Create and name a table and specify fields with their data types like: text, number, date/time, yes/no. Click on Create Then click on Table from the tables section Click on the arrow in the view section and choose Design view button © TCTC Name the Table Page 24 ECDL Module 5 Notes Start typing the field names and for each field name choose the data type like text, number, date/time, yes/no etc © TCTC Page 25 ECDL Module 5 Notes 5.3.2.2 Apply field property settings: field size, number format, date/time format, default value. It’s important that to apply field properties such as field size etc you need to be in design view. After choosing the data type at the bottom you will have a tab called General. From there you can modify the field size, number format, date/time format, default value. But the General tab will change according to the data type chosen. For the field size and default value just input the number that you need. 5.3.2.3 Create a validation rule for number, date/time, currency. Microsoft Access provides a variety of ways to control how users enter data into your database. For example, you can limit the data that a user can enter into a field by defining a validation rule for that field. If the data that a user enters into the field breaks the rule, Access will display a message telling the user what kind of entries are allowed. Create validation rules for number fields Let’s say you have a table with the following fields: Field Name: Name Surname Exam Result Data Type: Text Text Number You may need to set a validation rule on the result field restricting the numbers entered in this field to be not greater than 100. This will avoid mistakes, such as pressing an extra number while keying in results. © TCTC Page 26 ECDL Module 5 Notes To do this, follow the steps below: Click on the Exam Result field In the General Tab, click in the box provided for validation rule Type: <=100 This means that only values which are less than or equal to 100 will be allowed to be keyed in. Similarly, in any number field we can use the below symbols for creating validation rules: Create validation rules for date fields You might have a table that contains a field with date as the data type. It might also be the case that you wish to restrict the dates that can be entered in that particular field. Let’s say we have a database of a club, where only adults that were born from 19701980 can register. In the validation rule for the date of birth field we can type: Between 01/01/1970 and 31/12/1980 We can also use the mathematical symbols discussed earlier on with dates. For example, if you only wish to allow users that were born before 1990, you can enter one of the following validation rules: <01/01/1990 Or <=31/12/1989 5.3.2.4 Understand consequences of changing data types, field properties in a table. When changing data types or field properties in a table data could be lost as it will not match with the types you had entered. © TCTC Page 27 ECDL Module 5 Notes 5.3.2.5 Set a field as a primary key. Click on the field that you wish to set as a primary key. Click Primary key which is in the Design tab in the tools section. A key will appear at the left of the field name. Deleting a Primary Key In the Design view of the table right click on the field from which you want to remove the primary key setting. Click Primary Key. You will notice that the key symbol will no longer be displayed in the record selector. 5.3.2.6 Index a field (with, without duplicates allowed). Your primary key field will automatically be indexed so that duplicated entries are not allowed. However, you might need to index other fields in your table. In the General section of the Design view of the table click in the Indexed box and then click on the drop down arrow. You can set the index to allow or not to allow duplicate records: © TCTC Page 28 ECDL Module 5 Notes 5.3.2.7 Add a field to an existing table. To add a field to an existing table:Open the table Go to Design View Go below the last Field Name and type the field name you wish to add Add also the data type and Save 5.3.2.8 Change width of columns in a table. Open a table in Datasheet view. To resize a column: Do one of the following: To resize a column to a specific width, position the pointer on the right edge of the column you want to resize, as shown in the illustration and drag until the column is the desired size. To size a column to fit its data, double-click the right edge of the column heading. Note: You can't undo changes to the width of columns using the Undo command on the Edit menu. To undo changes, close the datasheet, and then click No when asked if you want to save changes to the layout of the datasheet. This will also undo any other layout changes you have made. 5.4 Retrieving Information 5.4.1 Main Operations 5.4.1.1 Use the search command for a specific word, number, date in a field. To search for a specific word, number or date in a field you first need to open the table in datasheet view. Then follow the steps below: Click in the field in which you need to search. From the Home tab in the find section click on Find © TCTC Page 29 ECDL Module 5 Notes In the Find What: field type the word / number / date that you wish to search for. Make sure that the Look In: field is set to your desired field. Click on Find Next. 5.4.1.2 Apply a filter to a table, form. Filters are basically simple queries that only apply to open tables or forms. Filters are best used for temporarily altering the view of the data in a table: by filtering out records that you don’t want. Apply filters to a table Let’s say we need to filter our table so that it only retrieves records of individuals who reside at Mosta. Open your table in datasheet view. Click on one of the records that shows ‘Mosta’ as the Town field. Click on the Filter by Selection icon from the home tab in the Sort and filter Section and choose Contains Mosta © TCTC Page 30 ECDL Module 5 Notes 5.4.1.3 Remove the application of a filter from a table, form. To remove the filter, click on Filter icon from the home tab in the Sort and filter Section and choose clear filter from locality. 5.4.2 Queries 5.4.2.1 Understand that a query is used to extract and analyse data. As tables grow in size they can have hundreds of thousands of records, which makes it impossible for the user to pick out specific records from that table. Queries were designed to overcome this problem. Practically, queries are used to extract and analyse data. 5.4.2.2 Create a named single table query using specific search criteria. From the Create tab click on Query Wizard Choose Simple Query Wizard © TCTC Page 31 ECDL Module 5 Notes From the Tables/Queries drop down arrow choose the table that you need Then choose the fields Then click on Next Then click on Next again Write a title for your query, choose between open the query to view information or Modify the query design and click Finish. The difference between open the query to view information or Modify the query design is that when we need to add some criteria to the query we use Modify the query design while we use open the query to view information when there’s nothing else to be done © TCTC Page 32 ECDL Module 5 Notes 5.4.2.3 Create a named two-table query using specific search criteria. From the Create tab click on Query Wizard Choose Simple Query Wizard From the Tables/Queries drop down arrow choose the table that you need Then choose the fields Then From the Tables/Queries drop down arrow choose another table that you need fields from Choose the fields again Then click on Next Then click on Next again © TCTC Page 33 ECDL Module 5 Notes Write a title for your query, choose between open the query to view information or Modify the query design and click Finish. Matching Text When you enter text into the criteria cell your text should be enclosed in quotes ("") to distinguish it from other expressions and operators that you may need to add. To match a word or phrase simply type the text you want to match. The query will find all the records that match the text exactly. Access will add the quote marks at each end. It is only necessary to enter the quotes yourself if you type text that might confuse the query. For example you may want to type a phrase that contains the words "and" or "or". Access would normally interpret these words as instructions. You can manually insert the quote marks at each end of the phrase to make sure the criterion means what you intend it to. This example will display all the records that contain the entry Mosta in the Locality field. © TCTC Page 34 ECDL Module 5 Notes 5.4.2.4 Add criteria to a query using one or more of the following operators: = (Equal), <> (Not equal to), < (Less than), <= (Less than or equal to), > (Greater than), >= (Greater than or equal to). Mathematical operators such as ‘>’ (greater than) or ‘<’ (less than) are normally used for specifying numbers and dates but can also be used for text. For example: <"N" would find all entries beginning with a letter lower than the letter N in the alphabet. In other words, all entries starting with the letters A - M. >="F" And <"H" would find all entries beginning with the letters F and G. Working with Numbers When working with numbers we normally use the mathematical operators to define the range of numbers from which we want to select. For example, where X represents a number: <X finds values less than X. >X finds vales greater than X >=X finds values greater than or equal to X <>X finds vales not equal to X It is important that your field type is correctly defined as a Number field for numerical queries to work properly. Here are some examples… To match a number Simply type the number that you want the query to find. This example will display the record(s) with the entry 385 in the Customer Number field. © TCTC Page 35 ECDL Module 5 Notes To find values less than a certain number Type a less than sign (<) followed by the number. This example will display all records with an entry less than 1000 in the Customer Number field. To find values in a range of numbers You need to use the expression “Between X and Y”, where X and Y represent the numbers at opposite ends of the range. This example will display all records with entries falling within the range 500-700 in the Customer Number field. 5.4.2.5 Add criteria to a query using one or more of the following logical operators: AND, OR, NOT When you need to use multiple conditions for a query, you can use the logical operators to combine conditions. – The And logical operator specifies that both conditions must be met – The Or logical operator specifies that one or the other of the conditions must be met • When you enter two conditions on the same row of the query design grid, an And condition is created. • If you enter two conditions that are on separate rows, an Or condition is created. Creating And condition in the design grid When creating criteria in the same row you are creating an And condition © TCTC Page 36 ECDL Module 5 Notes Creating Or condition in the design grid When creating criteria in the separate rows you are creating an OR condition 5.4.2.6 Use a wildcard in a query, * or %, ? or __. A wildcard is a special character that can stand for either a single character or a string of text. Wildcards are useful when you want the query to look for a range of different possible values, and also when you are not certain exactly what you are looking for but can give the query some clues to work with. The two wildcards we commonly use are the asterisk or star (*) and the question mark (?). 1. The asterisk (*) represents any string of text from nothing up to an entire paragraph or more. 2. The question mark (?) represents a single character only (although you could use, for example, two question marks to represent two unknown characters). For example: Yor* would find York, Yorkshire and Yorktown but not New York. Mar? would find Mark but not Mario, Martin or Omar. F*d would find Fred and Ferdinand but not Frederick. Like "Text*" To match text starting with a particular letter or string, type the letter or string of text followed by an asterisk. Access will add the expression "Like" and place quotes around your typing. This example will display all records that have an entry starting with S in the Company field. © TCTC Page 37 ECDL Module 5 Notes Like "*Text" To match text ending with a particular letter or string, type an asterisk followed by a letter or string of text. This example will display all records that have an entry ending with Plc in the Company field. 5.4.2.7 Edit a query: add, modify, remove criteria. To add or modify criteria for a query it’s important that you will be in the design view of that query. Click on the criteria of that particular field and add or change the criteria as you need. To remove the criteria simply place the cursor before the criteria and press the backspace button till you delete the whole criteria of that field. 5.4.2.8 Edit a query: add, remove, move, hide, unhide fields To insert additional fields to a query: 1. Display the query in Design view. 2. In the field list, double-click the field name/s which you want to add. The Field: (first row), in the design grid, will display the field name selected. The Table: (second row), in the design grid, will automatically display the name of the table from which you have selected the field. 3. Save the query. To remove fields from a query: 1. Display the query in Design view. 2. In the design grid, click the small grey cell above the name of the field to remove. The entire column will be highlighted. 3. Press DELETE key. © TCTC Page 38 ECDL Module 5 Notes Note that: You cannot undo deletions in queries in Design view. If you accidentally delete a field, you will have to add it again to the query. To move fields within a query: 1. Display the query in Design view. 2. In the design grid, click the small grey cell above the name of the field to move. The entire column will be highlighted. 3. Drag the column to the location where you wish to place it. To hide field/s from being displayed in the record set: 1. Display the query in Design view. 2. In the design grid, deactivate the check box/es in the Show: cells for the field/s that will not be displayed in the record set. In most cases such fields are added to the design grid for criteria purposes only. To unhide field/s so that these will be displayed in the record set: 1. Display the query in Design view. 2. In the design grid, activate (click) the check box/es in the Show: cells for the field/s that will be displayed in the record set. 5.4.2.9 Run a query. After having specified the criteria in a query, you have to RUN the query in order to see the results. To run the query press on the Run button in the Design tab in the Results Section © TCTC Page 39 ECDL Module 5 Notes 5.5 Objects 5.5.1 Forms 5.5.1.1 Understand that a form is used to display and maintain records. A form is used to display and maintain records. It is an easier and more practical way of entering data than through a table 5.5.1.2 Create and name a form From the Create tab click on More Forms and choose Form wizard From the Tables/Queries drop down arrow choose the table that you need Then choose the fields Then choose the layout and click Next Then choose the style and click Next Write a title for your Form, choose between open the query to view information or Modify the Form design and click Finish. © TCTC Page 40 ECDL Module 5 Notes 5.5.1.3 Use a form to insert new records. Double - Click on the form in which you wish to insert records. The form window will be displayed. Click on New Record from the Record at the bottom of the window to add a new record. 5.5.1.4 Use a form to delete records. Double - Click on the form in which you wish to insert records. The form window will be displayed. Go to the record you wish to delete and click on Delete from the Records Section and click on Delete Record. 5.5.1.5 Use a form to add, modify, delete data in a record. To add data simply do on the box you need to add data and star typing. For modifying data the same click on the box that you need to change place your cursor before or after that word, and type what you need. To delete data select the box that you need to delete and press delete from your keyboard 5.5.1.6 Add, modify text in headers, footers in a form. The Form Wizard is an essential tool for creating a form. However, you may need to modify the design of a form. For example, to add/edit a header or footer you will need to use the Form Design View. Go to Design View from the view button © TCTC Page 41 ECDL Module 5 Notes The form Design View window displays three sections: Form Header, Detail and Form Footer (scroll down to see the Form Footer). You will need to create a space between the Form Header section and the Detail section to enter header text. Likewise, you will need to create a space below the Form Footer if you wish to add a footer text. To add a header / footer: Click on the Label tool from the Controls Section: Create a label in the header or footer of your form and type in the text you wish 5.6 Outputs 5.6.1 Reports, Data Export 5.6.1.1 Understand that a report is used to print selected information from a table or query. You can use reports for a variety of purposes: some common examples are periodical sales summaries, stock lists, mailing lists and invoices. A report is used to print selected information from a table or query. The easiest way to produce your own reports is by using the wizard. You can choose from a large choice of different reports. The Report Wizard can construct the whole report according to your instructions. 5.6.1.2 Create and name a report based on a table, query. From the Create tab click on More Report wizard From the Tables/Queries drop down arrow choose the table/query that you need Then choose the fields © TCTC Page 42 ECDL Module 5 Notes Then choose if you need to do any grouping Choose by what you want to sort your report. Choose the layout and click Next Choose the style and click Next © TCTC Page 43 ECDL Module 5 Notes Write a title for your report, choose between open the query to view information or Modify the Report design and click Finish. 5.6.1.3 Change arrangement of data fields and headings within a report layout. While doing the wizard when doing step 4 you can choose the layout of the report and the orientation. If you wish to move the data fields go to design view and move the data field by drag and drop 5.6.1.4 Present specific fields in a grouped report by sum, minimum, maximum, average, count, at appropriate break points While doing the wizard when doing the sorting choose Summary options that will be available on that particular window and choose by what you want to group your report example by sum or minimum or maximum or average or count 5.6.1.5 Add, modify text in headers, footers in a report. The Report Wizard is an essential tool for creating a form. However, you may need to modify the design of a form. For example, to add/edit a header or footer you will need to use the Report Design View. Go to Design View from the view button © TCTC Page 44 ECDL Module 5 Notes The Report Design View window displays three sections: Report Header, Detail and Report Footer (scroll down to see the Form Footer). You will need to create a space between the Form Header section and the Detail section to enter header text. Likewise, you will need to create a space below the Report Footer if you wish to add a footer text. To add a header / footer: Click on the Label tool from the Controls Section: Create a label in the header or footer of your form and type in the text you wish 5.6.1.6 Export a table, query output in spreadsheet, text (.txt, .csv), XML format to a location on a drive. Choose the table Click on the External Data Tab Click on Excel in the Export Section Write the File Name Click OK © TCTC Page 45 ECDL Module 5 Notes Click Close 5.6.2 Printing 5.6.2.1 Change the orientation (portrait, landscape) of a table, form, query output, report. Change paper size. Choose the table, form, query or report. Click on the Microsoft office Button Click on Print Preview From the Page Layout Section choose between Portrait or Landscape Choose also the size from the Page Layout Section example A4 5.6.2.2 Print a page, selected record(s), complete table and 5.6.2.3 Print all records using form layout, specific pages using form layout. And 5.6.2.4 Print the result of a query. And 5.6.2.5 Print specific page(s) in a report, print complete report. Click on the Office Button. Point to Print, and then click on Print from the sub-menu The Print dialog box will be displayed as illustrated below © TCTC Page 46 ECDL Module 5 Notes In the Page range section choose whether you wish to print all the pages in the report etc or you can choose from which page to which page you want to print or choose if you want to print selected records In the Copies section specify how many copies of the same document you wish to print. Finally, click OK. . . © TCTC Page 47