Access XP Basics

Presented by Traci Terrill [email protected] ESC Region XV of Contents

Access XP ...... 3 Getting Started with Access...... 4 Creating a new ...... 5 Tables...... 6 Creating Fields in a Table...... 7 Building a Table in Design View...... 8 Create a Table by using Wizard...... 9 Creating a Form ...... 13 Using the Design Mode with Forms ...... 15 Entering Records into Forms ...... 16 Viewing Records in Datasheet View ...... 17 Formatting the Datasheet View ...... 17 Printing Records...... 17 Filtering...... 18 Using Saved Filters...... 19 Advanced Filtering ...... 19 Modifying a Table and Updating a Form ...... 20 Saving and Modifying Records ...... 21 Defining Relationships...... 22 Using Subdatasheets ...... 23 Using Select Queries...... 24 Modifying and Deleting a Select Query ...... 26 Saving Select Query Results...... 27 Range Queries...... 27 Select Queries involving “And”...... 28 Select Queries involving “Or” ...... 28 Query Criteria Wildcards...... 28 Creating a Report ...... 29

Access XP Basics 2 Access XP – A Relational Database

An Access database can be used to generate forms, queries, and reports from the data it stores.

What is a relational database?

A relational database stores data in one or more tables, which relate to each other through common values.

An example would be to have a table with all student personal information: name, address, phone, parent name, social security, etc. Then have another table with student name and locker number, network login, etc. Certain data about the student can be pulled from both tables while leaving the data you don’t need behind. Both tables have the student name which is the common value between both tables.

Basic Design of an Access Database

Tables – store info

Queries – ask questions, filter

Forms – enter info, edit

Reports – print info (calculations)

A database should be created based on a design. Designing a database is a three step process: 1. Determine what information should be stored. 2. Divide information into named tables. 3. Define the fields and determine the primary key for each table.

This handout will guide you through the very basic creation of an Access database.

Access XP Basics 3 Getting Started with Access

Click on Start, Programs, , and then to open the application.

Use the Task Pane on the right side of the window to begin a new database. Click on New File task pane, click on Blank Database.

Access XP Basics 4 Creating a New Database

Click on Blank Database under the New section on the Task Pane. The first requirement of starting a database is to assign it a file name and save it.

Save this database as Student Data and select Create.

Access XP Basics 5 Tables

A table is a collection of data about a specific topic, such as students, teachers, supplies, or products. A table is made up of fields that describe the content in the table. Each is called a record. Records are multiple entries of a field. Each student’s data would be considered a record. Student Name or phone number would be a field.

There are three types of methods to creating a table, design , using a wizard, and creating by entering data.

Primary Key – each table must have a primary key. This means that each record must have a unique value. An example of this would be social security number, network password, or student ID. A primary key is what makes the relational. A value in one table must have a relationship to value in another table.

Access XP Basics 6 Creating Fields in a Table

A data base is organized into fields that store data. A field is defined by its name, type, size and format.

Field Name Guidelines: • Make field names unique. • Choose the shortest possible name that accurately describes the contents of the field. • Use compete words instead of numbers and abbreviations. • Avoid special characters.

Consider the type of information you are going to put into your table. Determine an appropriate field name for each criterion. For example, student name could be a field name, but if you ever wanted to filter for last name only you would not be able to. Create a separate field name for first and last name.

To make it easier to decipher between the types of data in the field name it is suggested you put a three letter description of the data type in the field name. For example, txtFirstName or dteBirthday. This is only a suggestion and is not mandatory.

3 Letter Data Type Description Description Text or a combination of text and numbers Text txt without any calculations Long text or a combinations of text and Memo mem numbers Number Numbers to be used in calculations num Date/time Date and time dte Monetary values and numeric data used in Currency cur calculations Yes/no Can only contain a yes or no yen

Brainstorm the types of information you need to know about a student, list your ideas here. Examples are listed to get you started:

First Name Last Name Home Address Home Phone

Access XP Basics 7 Building a Table in Design View

Double click on Create table in Design view

The Design view is where the table is created. Each element of information must have a field name, be assigned a field type, and include a description for easy reference.

Use the previous data to group the information into tables. Start building your first table. Set Student ID as the primary key. Right click on the row and choose Primary Key from the menu. Save your table as tblStudentContact.

If you did not set a primary key this is the message you would see when you save your table. Access will put in an AutoNumber to hold the place for the Primary Key.

Access XP Basics 8 Create a Table by using Wizard

Double click on Create table by using wizard.

Determine what kind of table category best fits your needs, either business or personal. Each has a wide variety of sample tables to select.

Select a sample field and click on the > or click on the >> to move all the samples fields over from a particular table. Use the < or << to move any samples fields you do not need.

Select Personal, then Books under the Sample Table. Move Title, ISBNNumber, CopyrightYear, PublisherName, PurchasePrice, DatePurchased, and Book ID. Highlight BookID and select Rename Field. Rename to StudentID.

Click on Next.

Access XP Basics 9 Wizard Continued…

Assign the table the name tblStudentBooks

Decide if you want Access to set the primary key or if you want to set the primary key. If you set it, select the field that will be unique for each record. In this case, select StudentID. For this example, select No, I’ll set the primary key. Select Next.

Also decide what kind of data will make up the primary key: a number automatically assigned, a number you enter, or a number/letter combination you enter. For this example select the last option, Number and/or letters I enter when I add new records.

Access XP Basics 10 Wizard Cont…

If there were other tables in you database the Wizard would want to know if relationships needed to be created for you.

Click on the Relationships button to see the below window.

We will set up the relationships between the tables, select Next to continue to the final window. Select the second option to enter the data directly into the table and choose Finish to complete the wizard.

Access XP Basics 11 Wizard Continued…

The last window, select Enter data directly into the table.

Start entering data into the table.

Access XP Basics 12

Access XP Basics 13 Creating a Form

A form is a window that contains the fields of the table and is used for entering data and viewing records. A form displays only one record at a time, making data entry less error prone.

Select Form from the list of Objects. Double click on Create form by using wizard.

Select the tblstudentcontact table. The tables are located under Tables/Queries. The available fields are listed below. Move all the fields over by using the >> button. Then click on Next.

Access XP Basics 14 Form Wizard Cont…

Select the columnar form layout. Click on Next.

Select the Standard form style. Click on Next.

Title the form: frmStudentContact, leave the selection at Open the form to view or enter data. Click on Finish.

Access XP Basics 15 Using the Design Mode with Forms

If the field names are cut off, take the form into Design Mode and resize the fields. Click and drag the box in the upper left hand corner to separate the field name from the field entry box.

Access XP Basics 16 Entering Records into Forms

Record controls are displayed at the bottom of a form and are used for displaying a specific record in the table. The number of the active record and the total number of records in the table are displayed next to controls that scroll records. Record controls are dimmed if they cannot be used at the current time.

Displays a new record. Displays the first record. Displays the Displays Displays last record. the the next previous record. record.

A record is added by typing data into a blank record. If records already exist, the >* control is clicked to display a new blank record. Use the enter key or the tab key to move the insertion point from field box to field box. If the insertion point is in the last field of the form, the enter or tab key will move to the next record in the table or a blank record. Close a form by clicking on the close button X in the upper right hand corner of the form window.

Access XP Basics 17 Viewing Records in Datasheet View

A table viewed in Datasheet view shows existing records in rows one after another. A table is opened in Datasheet view by first clicking Tables in the database window to display table objects. Next double click on the table name.

The asterisk * that appears to the left of the row below the last record indicates where the next record entered will appear. It is not a blank record and can not be deleted or removed. The gray box to the left of each record is a record selector. Clicking a record selector makes that record the active record and displays the > symbol.

Formatting the Datasheet View

When a table is created, the columns in Datasheet view have a default width that may or may not entirely display a field’s name and data.

The width of a is changed by dragging the right boundary of the column. Or double click on the boundary of the column.

The order in which the fields appear in a table can be changed by dragging a selected field to a new location. Move the mouse above the column until a down arrow appears. Click to select the column and then drag the column to the new position.

Printing Records

A table displayed in Datasheet view can be printed by selecting the Print command from the File menu. If the data is too long or wide, consider changing the orientation to landscape in the File menu, Page Setup command.

Access XP Basics 18 Filtering

A feature of a relational database is its ability to perform queries. A query limits the records displayed to those that meet certain criteria. In Access, a filter can be used to query a database.

The first step in filtering is to determine the criteria. The filter criteria specifies the data that a record must contain in order to be displayed.

A filter can be applied to a displayed datasheet or form by clicking the Filter by Form button on the toolbar. This will display the datasheet or form in Filter by Form view.

Open the tblStudentContact table in datasheet view. Click on the Filter by Form button

Query criteria is specified by clicking a field box and selecting from the field list or typing a value. After specifying the criteria, a filter is applied by clicking the Apply Filter button on the toolbar. The records that do not meet criteria are hidden from view; they have not been deleted just not currently displayed. The record controls at the bottom of the table or form indicate how many records met the query criteria.

All the records in a table or form are again displayed by clicking the Remove Filter button on the toolbar.

Access XP Basics 19 Using Saved Filters

Filters can be named and saved so that they can be applied again and again without having to repeatedly select criteria. A filter is saved by clicking the Save As Query button on the toolbar, which displays the Save As Query dialog box. The Save as Query button is available in Filter by Form view before a filter is applied.

Typing a descriptive name for the filter and selecting OK add a named query to the database. A saved filter is applied by clicking on Queries in the database window to display the Queries objects. Next, double click on the filter name and the filter will be applied and the results displayed in datasheet view.

Delete a saved filter by selecting its name and pressing the delete key.

Advanced Filtering

A complex query can be applied to check for more than one value. If name and state are the criteria the query is using AND in the search. Both the criteria is placed on the Look For tab. Another type of complex query checks records for one value or another. This uses OR. Use the Or tab to complete this query.

Access XP Basics 20 Modifying a Table and Updating a Form

A table should be modified in Design view. Select table in the database window, select a table name, and then select the Design button on the database window toolbar. A table displayed in Datasheet view can be switched to Design view by clicking the View button on the toolbar.

A field is added by typing a name, selecting a type, and typing a description in the blank row after the last existing field in the table Design view. A field is renamed by placing the insertion point in a Field Name box in table Design view, editing the existing text, and then pressing Enter.

A form is not automatically updated when a table is modified. The best way to update a form is to create a new one. Give it the same name as the original but select yes to replace the existing form with the new one.

Access XP Basics 21 Sorting and Modifying Records

Placing records in a specified order is called sorting. In Access, records can be sorted in either ascending or descending order based on the data in a specified field.

The sort ascending and sort descending buttons on the toolbar are used to sort records. Clicking on the sort button sorts the data in the table according to where the was placed in the table. Sorting the records of a table does not affect the order of the records in a form.

Records can be modified by adding new records, changing the data in existing records, and deleting records. It is best to use a form to modify records. A new record can be added by using the >* button at the bottom of the form. Changing data in an existing record is called updating. Click inside the data entry box to update the information. The delete record button X is used to delete the current record displayed on a form.

Access XP Basics 22 Defining Relationships

Two tables are related when a field in one table corresponds to a field in another table. Every table in a relational database must be related to at least one other table in a database. Access needs to know the relationships between tables so that data can be joined appropriately. For two fields to define a relationship, the type of data they store must be the same, such as two text fields or two numeric fields. The field names are also typically the same, but this is not necessary.

Relationships are defined by clicking the Relationships button on the toolbar or selecting Relationships from the Tools menu, which displays the Relationships window.

Clicking a table name then selecting Add adds that table to the Relationships window. Clicking Close removes the Show Table dialog box. All of the tables in a database must be added to the Relationships window if relationships have not been defined.

A relationship is created by dragging a field from one table to a related field in another table. When a field is dragged into another table, it appears as a small box. When the mouse is released the Edit Relationship window appears. Create is selected to define the relationship. Cancel can be selected if the fields do not correspond. Save the relationship by clicking on the Save button on the toolbar or any other method. Close the relationship window by clicking on the X in the upper right hand corner of the window. If a table needs to be edited after a relationship is established, the relationship must be deleted.

Access XP Basics 23 Using Subdatasheets

Subdatasheets are available in Datasheet view when relationships have been defined for a database. A subdatasheet shows records from another table that are related to a particular record. A + is displayed next to each record of a table when subdatasheets are available. Clicking the + displays the subdatasheet for that record. Clicking the – removes the subdatasheet.

Access XP Basics 24 Using Select Queries

Another way to view specific data in a relational database is by applying a select query. A select query can include fields from any table and used the relationships between tables to determine which data to display. The results of a select query are displayed in a datasheet.

Select Queries from the objects list on the database window. Double click on Create query in Design view.

Select the tables and click on Add to add the tables from the Show Table window to the Query window.

Notice the line indicating the tables are related. The tables in a select query must be related for the query to work properly.

Access XP Basics 25 Using Select Queries cont….

The design grid is where fields to be displayed by the select query must appear. A field is added to the design grid by dragging it from the table in the top of the window to a Field box in the design grid.

Click on the Run ! button to display the results of the query. The results are displayed in Datasheet view.

A select query is saved by clicking the Save button on the toolbar. A save as dialog box will appear, type in a descriptive name for the query. To apply a saved query, open the queries area on the database window and double click on a query name. The query will be applied and the results will be displayed.

Access XP Basics 26 Modifying and Deleting a Select Query

A select query can be modified in Design view. If the select query datasheet is displayed, clicking the View button on the tool bar switches to Design view. A query can also be displayed in Design view by clicking Queries in the database window, clicking the query name, and then clicking the Design button on the Database window toolbar.

A table is removed from Select Query Design view by clicking the table and then pressing the Delete key. When a table is removed, any of its fields and corresponding criteria are removed from the design grid. A table is added to Select Query Design view using the Show table dialog box, which is displayed by selecting Show Table from the Query menu or clicking the Show Table button on the toolbar.

Dragging a field to the design grid adds the field and moves existing fields to the right.

A query is deleted by selecting its name in the database window and then pressing the delete key.

Access XP Basics 27 Sorting Select Query Results

The results of a select query can be ordered based on the entries of a particular field. A sort order is specified by selecting an order from the Sort list of a field in the Select Query design grid. When the query is run, records in the select query datasheet are sorted.

Range Queries

A range query has criteria that include different values. This kind of criteria is specified using relational operators, which are used to compare values:

= equal to < less than > greater than <= less than or equal to >= greater than or equal to <> not equal to

The criteria is typed in the criteria line in the design grid.

Access XP Basics 28 Select Queries Involving “And”

Complex queries with “and” in the criteria can require multiple entries in the Criteria row of a select query design grid.

Select Queries Involving “Or”

Complex queries with “or” in the criteria require the or row of a select query design grid. Criteria is required on two rows or it is an “and” complex query.

Query Criteria Wildcards

Query criteria can include wildcards. A wildcard is a character that matches any one or more characters. The asterisk (*) and question mark (?) are two wildcards. The * wildcard matches any number of characters or no characters at all. The ? wildcard matches any one character or no character at all. When wildcards are used in criteria, Access uses the Like operator to determine a match.

Access XP Basics 29 Creating a Report

Reports are a powerful database feature that presents data for printing in an organized manner with a descriptive title and headings. The simplest report uses a single table or select query database. A report can also include any combination of fields from multiple tables.

A report is created by clicking Reports in the database window. Double click the create a report by using wizard. Add the fields to the report by first selecting the table or query to run the report on. The fields from the table or query are displayed in the available fields list. Selecting a field the clicking on the > moves the field to the selected field list. Click on Next when all the needed fields are moved.

Next select a view. Clicking on a view determines how the report data is organized. If only one table is used in the report, then there is only one possible way to organize the data and the dialog box is not displayed. When multiple tables are used in a report, the views correlate to the fields shown in each table’s subdatasheet.

Select the data grouping. Grouping data can make a report easier to comprehend. Selecting a field and then clicking > groups the data in the report by this field’s data.

Access XP Basics 30 Creating a Report cont…

Select the sort order. A report can be sorted based on the data in the field. Select a field and then choose either sort ascending or descending.

Select the layout. Clicking a layout option shows a portion of the layout style in the left side of the dialog box. Landscape orientation allows more fields to fit across the paper.

Select the report style. Give the report a name.

Access XP Basics 31