Access New Book

Embed Size (px)

Citation preview

  • 8/12/2019 Access New Book

    1/170

    University Technology Training Center

    Access 2007:

    Basic Database Development

  • 8/12/2019 Access New Book

    2/170

  • 8/12/2019 Access New Book

    3/170

    0 7 . 0 8 . 2 0 0 9

    U N I V E R S I T Y T E C H N O L O G Y T R A I N I N G C E N T E R

    Access 2007:Basic Database Development

    2009 Regents of the University of MinnesotaUniversity Technology Training Center

    All Rights Reserved

    uttc.umn.edu

    The University of Minnesota is committed to the policy that all persons shall have equal access to its programs, facilities, and employment without regard to race,color, creed, religion, national origin, sex, age, marital status, disability, public assistance status, veteran status, or sexual orientation.

    This publication/material can be made available in alternative formats for people with disabilities. Direct requests to:

    University Technology Training Center190 Shepherd Labs

    100 Union Street SoutheastMinneapolis, MN 55455

    [email protected]

  • 8/12/2019 Access New Book

    4/170

  • 8/12/2019 Access New Book

    5/170

    U N I V E R S I T Y T E C H N O L O G Y T R A I N I N G C E N T E R i

    Table of Contents

    LESSON 1 1 INTRODUCTION TO

    DATABASES 1 Database Design Vocabulary 1Relationships 2Design Process 4

    LESSON 2 7 BUILDING A DATABASE IN

    ACCESS 7 Create an Access Database 7Set Access Options 10Creating Tables 14Exercise 1: Creating Tables 20Creating a Join Table 21

    LESSON 3 23 SETTING FIELD PROPERTIES 23

    Resizing text fields 24Input Masks 25Default values 28Format number fields 30Exercise 2: Setting field properties 32

    LESSON 4 33 CREATING RELATIONSHIPS 33

    Print the design 37Removing Tables from the Diagram 38Deleting or Editing Relationships 38

    LESSON 5 39 MODIFYING TABLES AND

    RELATIONSHIPS 39 Adding the New Foreign Key Field 40

    LESSON 6 43 CREATING INTERFACES TO

    INTERACT WITH DATA 43

    Using Forms vs. Tables for dataentry 43Creating the Member Status typeEntry Form 44Exercise 3: Creating Entry FormsUsing Multiple Items Form Option 50Handling One-to-ManyRelationships with Subforms 54Exercise 5: Creating a Subformusing Autoform 62Linking the Main form and Sub Form 69Navigating Records and EnteringTest Data 72Creating Forms using the wizard 73Exercise 6: Creating the CD entryform using the Wizard 77

  • 8/12/2019 Access New Book

    6/170

    U N I V E R S I T Y T E C H N O L O G Y T R A I N I N G C E N T E R i i

    Adding to combo box lists on thefly 81Finding a Record on a Form 84Using a Combo Box to Find Records

    on the Form 87Creating the Member CD Form andSubform in Design View 91Date picker 99

    LESSON 7 101 EDITING A FORM 101

    Modifying a Form 101

    LESSON 8 105 QUERIES 105

    Creating a Query using the QueryWizard 105Exercise 7: Creating a Query Usingthe Wizard 112

    Adding Criteria to a Query 114Creating a Query in Design View 116Exercise 8: Creating a Query inDesign View 119End of Exercise 120

    LESSON 9 121 REPORTS 121

    Creating a Report Using the AutoReport option 121Exercise 9: Creating a Report Using

    Auto Report 125Creating a Report Using the Wizard 126Exercise 10: Creating a ReportUsing the Wizard 131

    LESSON 10 137 F INAL TOUCHES 137

    Menu 137Database Maintenance andBackups 143

    APPENDIX A 147 USING THE LABEL REPORT

    W IZARD 147

    APPENDIX B 151 CREATING A QUERY USING

    AGGREGATE FUNCTIONS 151

    APPENDIX C 155 EXPORTING QUERY RESULTS155

    APPENDIX D 159 CREATING A MEMBER

    ADDRESS REPORT USING

    THE W IZARD 159

    APPENDIX E 163 EXPORTING A REPORT 163

  • 8/12/2019 Access New Book

    7/170

    U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r 1

    Introduction to Databases

    Database Design Vocabulary

    Database

    Field: One piece of information you want to track in your database

    o Examples: Name or Birth Date or CD Title

    Record: A group of fields containing data about one particularperson, event, item, etc.

    o Examples: CD Title and Artist and Genre and Release Year

    Table: A group of records

    o Examples:

    TITLE GENRE PERFORMER RELEASE DATE OWNER

    The Best of Van Morrison Rock Van Morrison 1990 Amy Jones

    Positive Friction Americana Donna the Buffalo 2000 Amy Jones

    Natural Brazilian Celso Fonseca 2003 Amy Jones

    Sketches of Spain Jazz Miles Davis 1991 Amy Jones

    Kind of Blue Jazz Miles Davis 1991 Amy Jones

    Rice, Rice, Hillman and Pedersen Bluegrass Rice, Rice, Hillman and Pedersen 1999 Amy Jones

    Man of Constant Sorrow Bluegrass Ralph Stanley 2001 Amy Jones

    Sketches of Spain Jazz Miles Davis 1991 Andy Jackson

    Kind of Blue Jazz Miles Davis 1991 Andy JacksonMan of Constant Sorrow Bluegrass Ralph Stanley 2001 Andy Jackson

    I Wonder Where You Are Tonight Bluegrass Del McCoury 2002 Andy Jackson

    A Day Without Rain New Age Enya 2004 John Smith

    In Pieces Country Garth Brooks 2002 John Smith

    American Idiot Pop Green Day 2004 John Smith

    Lesson1

    Lesson

    1

  • 8/12/2019 Access New Book

    8/170

    L E S S O N 1 :

    I N T R O D U C T I O N T O DA T A B A S E S

    2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Example of a table in a flat/Excel file

    Example of a table in Access

    Best Practice

    When you expect multiple values or repeating data in a table, youshould consider splitting the table into two or more related tables.For example, in the flat/Excel file shown above, Miles Davis is listedseveral times, as are some of the Genres and Owners.

    Relationships

    Relationship diagram showing the relationships between various tables

  • 8/12/2019 Access New Book

    9/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 3

    Types of Relationships

    One-to-Many: The most common type. For every record in Table A,there are multiple records in Table B

    o Example: One Member may have many Addresses (work,home, cabin, etc.)

    Many-to-Many: For every record in Table A, there are multiplerecords in Table B, and vice versa. In this case, a third tablecalled aJoin Tableneeds to be created, which will contain only uniquevalues.

    o Example: One Member may have many CDs, and the sameCD may be owned by many Members

    Best Practice

    The Join Table name should be a combination of the two many-to-many tables (e.g., tblMemberCD). The Primary Key can be the JoinTable name or the first initial of each table name followed by ID(e.g., MemberCDID).

    One-to-One: The rarest type, it is used for security and organization(i.e., avoiding empty fields that only apply to some records in the

    table)

    Primary Key: Auto-numbered, unique ID for internal tracking andfor matching records between related tables

    Foreign Key: A number-type field in a related table pointing back tothe Primary Key in another table

  • 8/12/2019 Access New Book

    10/170

    L E S S O N 1 :

    I N T R O D U C T I O N T O DA T A B A S E S

    4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Best Practice

    The Primary Key should be the table name plus ID (e.g.,

    MemberID) and should be the same name in the table where it isused as a Foreign Key. (There are exceptions. In this course, theForeign Keys LoanedToID and MemberID in tblMemberCD tableboth go back to the Primary Key MemberID in tblMember.)

    The Primary Key should always be the first field in each table,followed by any foreign key(s).

    Primary Keys should never be actual datanot even somethingunique like a Social Security number or Student ID. These values areobtained from an outside source and, while seemingly unique and

    reliable, could produce data entry errors.

    Design Process

    These preliminary steps are done on paper.

    Statement of Purpose

    Example: CD Club between friends: Database needs to catalog CDsowned by each member and track the loaning of CDs betweenmembers. Classify all CDs by Genre, and list performer, yearreleased, and value for each CD. Provide reports, such as memberand CD listings.

    Best Practices

    Use Prefixes in form or object names to denote different object types(e.g., tbl for tables).

    Avoid using spaces or special characters in object and field names.

    For single, repeating values requiring consistent data entry andsearching, use a Lookup Table or Value List.

  • 8/12/2019 Access New Book

    11/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 5

    Value List: Works well for single, static, short lists of informationthat is restricted to a list (e.g., Address Type). It is not easilyupdatable.

    Lookup Table: Better for longer lists or those with multiple fields. Itis easier to add additional values at a later date. You can choose alevel of restriction (e.g., Genre).

    Determine Fields

    Best Practice

    Avoid multiple yes/no fields or fields that will be consistently leftempty. Consider breaking out into a separate table or creating aLookup Table of values to choose from.

    Keep items such as names (first name and last name) in separatefields. It is far easier to join those fields when needed than it is toseparate a first name, last name, suffix, etc., to use in a mail merge orsimilar function. This also keeps them consistently in the same place.If you only have one field, you have little or no control over theorder of entry.

    Consider an active/inactive status field instead of deleting recordsand losing history (such as Member Status).

  • 8/12/2019 Access New Book

    12/170

    L E S S O N 1 :

    I N T R O D U C T I O N T O DA T A B A S E S

    6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Define Relationships

    Refine and Test

    Now is the time to review your design before you start creating your Accessdatabase. It is harder to make changes once you have data in the tables.

    Access is a database management system that also includes forms, queries,reports, etc. for ease of interacting with your data and extracting data fromtables. Many other database systems (e.g., Microsoft SQL) require aninterface be created in another program.

    Forms: Used for viewing, adding, and updating data

    Queries: Used to ask Access to return a selected portion of your data

    Reports: Used to format the data for printing

  • 8/12/2019 Access New Book

    13/170

    U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r 7

    Building a Database in Access

    Create an Access Database

    The first step to creating an Access database is to create and name thedatabase file that will store all of the tables, forms, etc. The file will be givena *.accdb extension automatically.

    Anytime you open a database, an .laccdb file is created. The .laccdb file isused to store computer/user names and to control record-locking in shareddatabases. The .laccdb file always has the same name as the opened databaseand is located in the same folder. Whenever the last user closes the database,the .laccdb file is deleted.

    1. Open Access

    StartProgramsMicrosoft OfficeMicrosoft Office Access2007

    Lesson2

    Lesson

    2

  • 8/12/2019 Access New Book

    14/170

    L E S S O N 2 :

    B U I L D I N G A DA T A B A S E I N A C C E S S

    8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    2. Create a new database

    Click on Blank Databasein the upper left corner

    The window pane on the right hand side will change to:

    3. Type in the name you want to give the database (in our case:CDClub). The .accdb extension will be added automatically for you.

  • 8/12/2019 Access New Book

    15/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 9

    4. Choose where you want to save the database by clicking on thebrowse folder icon.

    Browse to and select yourDesktop Access 2007 Basics folder

    5. Then click Create.Access 2007s new interface will open initially to a newtable in datasheet view.

    Before proceeding we need to view the Security Warning :

    6. Click onOptions

  • 8/12/2019 Access New Book

    16/170

    L E S S O N 2 :

    B U I L D I N G A DA T A B A S E I N A C C E S S

    1 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    7. ChooseHelp protect me from unknown content. This will turn offMacros that could potentially do harm to your database or computer.

    8. ClickOK

    Set Access Options

    The Access 2007 interface

    The interface for 2007 has changed significantly. Access is using the sameribbon menu system similar to other Office 2007 applications such as Wordor Excel.

    Access 2007 gives us an initial table to work with in datasheet view. Beforewe start creating tables, there are a few settings to consider changing.

  • 8/12/2019 Access New Book

    17/170

  • 8/12/2019 Access New Book

    18/170

    L E S S O N 2 :

    B U I L D I N G A DA T A B A S E I N A C C E S S

    1 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    3. Select Object Designersfrom the left hand pane

    Access 2007 has the default for text fields set at 255 instead of the old default of50. That is much larger than needed for most fields and would eat up too muchspace. We will set this to a more reasonable 3 5.

  • 8/12/2019 Access New Book

    19/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 3

    Access has a new view called Layout view, its a cross between design view andform view. It lets you make changes to the design while seeing data in the fieldsat the same time. We will not be using this view in class and because it can beconfusing to know what view you are in, we will disable it during class. That

    option is on the Current Database tab (these options only apply to thedatabase you are currently editing.)

    4. Uncheck Enable Layout View for this Database

    5. After the changes have been made click OK

  • 8/12/2019 Access New Book

    20/170

    L E S S O N 2 :

    B U I L D I N G A DA T A B A S E I N A C C E S S

    1 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Creating Tables

    The first step is to create all the tables we will need in our database.

    Access gives us an initial table to work with in datasheet view. It includes aprimary key simply called ID. You want to give the primary key a moremeaningful name so it is readily apparent which table that ID belongs to. Wewill follow our best practice of naming the primary key as the table namefollowed by ID (with no spaces in the field name)

    Before we do that we are going to switch to design view. (We will do all ofour design work with our tables in design view).

    1. Click the Viewtoggle button on the far left side of the ribbon.

    Important Note!

    For all objects we work with in this class, we will be switching backand forth between Design Viewof the object and the end user viewor result (Data Sheet, Form, query results, or report results). Themethod of changing the view is identical.

    2. Access will ask you to save the table first.Type in the table name(tblMemberwill be the first table we create)

    3. Click OK

  • 8/12/2019 Access New Book

    21/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 5

    On the left hand side is the Navigation pane(formerly Object Browser) thatwill show all of the tables, forms, queries and reports in the currentdatabase.

    On the right hand pane is the design view of the tblMember

    The top section of the table Design View screen has three columns for entryof Field Name, Data Type, and Description.

    Field Name:

    Keep it short but meaningful

    No spaces or special characters

    Primary Key should be the table name plus ID (i.e., if the table is

    called tblAddress, the Primary Key should be AddressID)

    Add a DateCreated field to every table, which date stamps whenthe record was first entered

    Avoid using keywords as field names (e.g., Date, Time, Now, Delete,User, Count, Value etc.). You can, however, have them as part of afield name (e.g., DateEntered)

    NEW to 2007:

    Access now will warn you if you enter a field name that is a keyword, such as Valuein our CD table.

  • 8/12/2019 Access New Book

    22/170

    L E S S O N 2 :

    B U I L D I N G A DA T A B A S E I N A C C E S S

    1 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Data Type options:

    AutoNumber: Auto incrementing number used for Primary Keys.

    Number: Can contain only numeric values that you may need to use incalculations, also used for all Foreign Keys.

    Text: Allows for Alphanumeric data (letters, numbers, characters, etc.). Textis the default data type. The default width is now 255, which is themaximum.

    Memo: Alphanumeric Text field that allows for 65,535 characters. Use whenyou need a very long note or description field.

    Date/Time: Contains a date and/or time value. Dates are automaticallyvalidated against the calendar. Date formats are determined by the

    Regional Settings on each PC. If those settings have been changed,you may get unexpected results.

    Yes/No: Displays as a checkbox and stores one value (yes or no, true orfalse). Access stores a No value as 0 and a Yes value as -1.

    OLE Object: Used for storing files from other applications (pictures,spreadsheets, etc.).

    Hyperlink: A link to a website, network document, or for sending to an emailaddress (if you include mailto: in front of the email address).

    Description:

    Optional wording to describe what the field is used for. This informationwill show up on a form as a screen tip if you hover over the field so it canalso be used as tips for data entry.

    1. Create the following tables in Design View

    tblMember, which we have already started

    tblMemberAddress

    tblCD

  • 8/12/2019 Access New Book

    23/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 7

    2. Enter the fields and their data types. You can select the data type bypicking from the list, or you can just start typing the word and it will findand display the closest matching data type for you.

    3. Once you have entered all the fields and their corresponding fieldtypes, closeand savethe table design. You will be asked to confirm

    design changes on a table, form etc.

    4. Click Yes

    5. To create another table click on the Createtab on the Ribbon

  • 8/12/2019 Access New Book

    24/170

    L E S S O N 2 :

    B U I L D I N G A DA T A B A S E I N A C C E S S

    1 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    6. Then Click Table

    7.Switch to

    Design View

    8. Save this table as tblMemberAddress

  • 8/12/2019 Access New Book

    25/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 9

    Note:

    Fields such as Zip and phone are created as text fields instead of

    number fields in order to apply input masks for controlling the dataentry format (also in case you need to enter foreign Zip codes.)

    9. Repeat for tblCD

    Note:

    If you use Valueinstead of CDValueyou would get the followingmessage:

    Click OKand correct the field name.

  • 8/12/2019 Access New Book

    26/170

  • 8/12/2019 Access New Book

    27/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 2 1

    Creating a Join Table

    The Join Table is necessary for our many-to-many relationship. It has the

    usual Primary Key plus two Foreign Keys pointing back to the tables in themany-to-many relationship. It also contains another Foreign Key pointing tothe Member table again, except this time it is tracking which Member the CDis loaned out to at the time. We cant use MemberID again so we will call itLoanedToID. A join table is created in the same way as any other table,using design view.

    Best Practice

    The Join Table name should be a combination of the two many-to-

    many tables. The Primary Key can be the Join Table name or firstinitial of each table name followed by ID.

    Note

    When working with an existing database, you may or may not seesome form of object-naming conventions and proper field/tablenames. Changing the names of tables and fields may affect manyareas of your database, from relationships to forms and reports topossible VBA code behind the scenes. Use extreme caution whenchanging names if you are not sure where an object is used and how

    to correct errors that may surface after such a change.

  • 8/12/2019 Access New Book

    28/170

  • 8/12/2019 Access New Book

    29/170

    U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r 2 3

    Setting Field Properties

    There are more options we can set besides data types on our fields. Theseoptions allow us to control or improve data entry such as limiting field sizes,adding formatting for phone numbers, or auto filling common values intofields.

    Best Practice

    Set all the format properties and options at the table-level so theypropagate through the forms, queries, and reports.

    The General Tab

    The bottom section of the Table Design View screen has two tabs. TheGeneral tab content varies based on the data type of the field currentlyselected. In the General tab, you can set field properties such as size, format,Input Mask, default value, etc. The Lookuptab is used for creating lookupsfor foreign key fields to the corresponding primary key.

    General tab for a Text field

    Lesson3

    Lesson

    3

  • 8/12/2019 Access New Book

    30/170

    L E S S O N 3 :

    S E T T I N G F I E L D P R O P E R T I E S

    2 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    General tab for a Number field

    Resizing text fields

    The default number of characters for text fields in Access is now 255, which

    is the maximum for a text field. In most cases that is too large and will wastehard drive space. At the beginning of class we set that property to a morereasonable and space saving number of 35. That is still too large for somefields, and too small for a few others. You can also use the length of the fieldto control what is entered into the field.

    NOTE:

    If you are working with a table that has data in it already, you maycut off existing data in that field if it is longer than the new field size

    you select. Access will display a warning message before it appliesthe change so you have a chance to cancel.

    1. OpentblMemberAddressin Design View by right clicking on it andchoosing Design View

    2. Select the Statefield

    3. Click on the Field Sizevalue in the General tab

    4. Change the value to 2

  • 8/12/2019 Access New Book

    31/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 2 5

    5. Repeat the same for the following fields:

    Zip:

    Field size of 9(to allow for ZIP + 4)

    Phone:

    Field size of 10

    Input Masks

    Input Masks are used for consistent data entry and formatting of dates,phone numbers, and zip codes. Added characters (/ - ( ) , etc.) are fordisplay onlythey are not saved as part of the data value. The field must betext, not numeric. If the Input Mask is added later, it will only show

    formatting correctly if it consists of straight numbers with no preexistingformatting. If you are working with existing data that has characters in thefield (such as / or -), remove the extra charactersmanually or by using aSearch/Replaceand the data will then correctly display with the choseninput mask.

    1. Select the Phonefield in tblMemberAddress

    2. Click in the Input Maskfield in the Generaltab.

  • 8/12/2019 Access New Book

    32/170

    L E S S O N 3 :

    S E T T I N G F I E L D P R O P E R T I E S

    2 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    The (ellipses) button will appear to the right of the field

    3. Click on the ellipses buttonto display the Input Mask Wizard

    4. You will be asked to save changes made to the table design

    5. Click Yes

    6. The input mask wizard will appear.Choose the Phone Number option(first one in the list)

  • 8/12/2019 Access New Book

    33/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 2 7

    7. In the Try Itsection, type in a phone number and see how it works.

    Note:

    With all Input Masks, if you tab into the field, the cursor will start atthe beginning. If you click in the field, it will start wherever youclick, and you have to move to the beginning of the field in order totype the data correctly into the Input Masks format.

    8. When you are done testing the Input Mask, click Finish. This is whatthe phone number input mask will look like in the general tab.

  • 8/12/2019 Access New Book

    34/170

    L E S S O N 3 :

    S E T T I N G F I E L D P R O P E R T I E S

    2 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Default values

    Default values can save data entry time for a field where most of the records

    entered will have the same value (i.e., most of the CD Club members will befrom Minnesota). The value entered can be easily changed for the exceptionsthat occur. A default value will only be present in new records. Existingrecords will not be affected.

    In order for our DateCreated field in each table to work, we need to add acommand into the default value. Default values apply only to new records.So every time there is a new record, we want to put in todays dateautomatically.

    1. Select the Statefield in tblMemberAddress

    2. In the Default Value field on the general tab, type MN

  • 8/12/2019 Access New Book

    35/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 2 9

    3. When you tab off the field it will put double quotes around the value.

    4. Choose the Countryfield

    5. In its default value type USA

    6. Select the DateCreatedfield

    7. In the Default Value field, type Date()

    Note:

    Be sure to include both parentheses! This will date stamp thecreation of a new record when it is added to the table. If you wantedto be more precise, you could use the command Now(), whichincludes both date and time.

  • 8/12/2019 Access New Book

    36/170

    L E S S O N 3 :

    S E T T I N G F I E L D P R O P E R T I E S

    3 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Format number fields

    Integer (the default number type) does not allow decimal places and will

    automatically round up or down even if you specify it should have 2decimals. If you need to have decimal places in a number value, you willneed to use the Single or Double formatdepending on how large thenumber entered will be.

    Byte: 0 to 255 (rounds up or down)

    Integer: -32768 to 32767 (rounds up or down, default number type)

    Long Integer: -2,147,483,648 to 2,147,483,647 (rounds up or down,default for Primary Key auto number fields)

    Single: -3.4x1038to 3.4x1038(up to 7 decimal places, will not round)

    Double: -1.797x10308 to 1.797x10308 (up to 15 decimal places, will notround)

    Prevent rounding of numbers with decimals

    1. OpentblCDin Datasheet View by double clicking on the table namein the Object Navigation Paneon the left side

    2. Type 14.99in the CDValuefield.

  • 8/12/2019 Access New Book

    37/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 3 1

    It will round up to 15 because by default it is an integer type.

    3. Hit ESCto undo the data entry

    4. Change to Design Viewof tblCDby clicking on the View toggle in theupper left.

    5. Click on the CDValuefield to select it

    6. Change the DataTypeto Currency

    7. Switch back to Datasheet View and type in 14.99. It will now displayas $14.99 and will not round.

    8. Hit ESC to undo the data entry.

    9. Close and Save the design changes to tblCD

  • 8/12/2019 Access New Book

    38/170

  • 8/12/2019 Access New Book

    39/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 3 3

    Creating Relationships

    In Access, you create the relationships between tableswhich youvepreviously defined on papervisually through the Relationship Window.

    Setting up the relationships here tells Access how the tables within thisdatabase are linked to each other. If you set up the relationships this way,the links between tables will carry through anytime you use the tables in aform, query, or report.

    8. Click on the Database ToolsTab

    9. Click on Relationships

    Lesson4

    Lesson

    4

  • 8/12/2019 Access New Book

    40/170

    L E S S O N 4 :

    C R E A T I N G R E L A T I O N S H I P S

    3 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    10.The Show Table dialog box will appear.Select all tablesin the databaseat once by holding down your shift key and click on the first table inthe list, then the last table.

    11.Click Addthen click Close

    Note:

    If the Show Table dialog box is not open, you can right click in ablank section of the relationships window and choose Show Table

    or use the Show Tablebutton on the Designtab

    12.Once you have all the tables showing in the window, you canrearrange them to look like your paper diagram by simply dragging

    them around the window.

  • 8/12/2019 Access New Book

    41/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 3 5

    Create the lines to connector relatethe Primary Keys to their respectiveForeign Keys, as on our paper diagram.

    13.Clickon the Primary Key in one table and dragit over to the Foreign

    Key in the related table. When you release the mouse you will see the EditRelationshipsdialog box.

    Important Notes!

    These fields must be of the same data type to be related. If not, youwill get an error message and will have to return to the table designand make the necessary corrections. Only one relationship is allowed

    between any two tables.

    14.Select Enforce Referential Integrity

    On the Edit Relationships window, there is an option that should be checked forall tables: Enforce Referential Integrity, which prevents a record from being

    Verify you have selected thecorrect fields!

  • 8/12/2019 Access New Book

    42/170

    L E S S O N 4 :

    C R E A T I N G R E L A T I O N S H I P S

    3 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    deleted in one table when there are related records in the other table. This optionaids in data integrity by not allowing deletion of data creating orphanrecords. For example, you wouldnt want someone to delete a CD from thedatabase that multiple people own and may be out on loan.

    Note:

    In Access 2003, setting Referential Integrity also acted as a requiredfield setting. Setting Referential Integrity between Genre and CD,for example, will prevent you from adding a CD record withoutselecting a Genre as well. If you have data in the tables already,Access will not allow you to set Referential Integrity until all recordsmeet this requirement. This was not the case before 2003 and hasbeen changed back in 2007 so that it does not create the requiredfield property.

    15.Click Create

    16.Repeat for all tables in the database

    17.Close and saveyour relationship design

  • 8/12/2019 Access New Book

    43/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 3 7

    Print the design

    You can print out the design to reference as you are working on the

    database, to keep track of changes made or to present to a manager or enduser.

    1. Return to the relationships window using the Database Tools tab.

    2. Select the Relationship Report

    3. Switch to Landscapelayout

    4. After you have printed the report close the report preview windowusing the Xin the upper right hand corner.

  • 8/12/2019 Access New Book

    44/170

    L E S S O N 4 :

    C R E A T I N G R E L A T I O N S H I P S

    3 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    5. Choose Nowhen it asks to save the report.

    Removing Tables from the Diagram

    If you accidentally add a table to the window more than once, it will add thetable again and name it [tablename]_1.

    To remove the extra table, just select the table and hit Delete. (You are notdeleting anything from the database itself.)

    Deleting or Editing Relationships

    Double click on the relationship line drawn between two tables to edit therelationship. Right clicking on the line will also give you the Edit option, aswell as the option to delete the relationship. Removing a table from therelationships diagram that has a relationship link to another table will notremove the relationship itself. To completely remove the relationship, youhave to delete the relationship beforeyou remove the table from the diagram.

  • 8/12/2019 Access New Book

    45/170

    U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r 3 9

    Modifying Tables and Relationships

    Often in the process of creating the tables and relationships, in the refine andtest stage, you may find that you need to rethink part of your design. Its agood idea to consider having a status field in your main table of the database(in our case tblMember). The primary reason is after a while the number ofrecords in the table will increase, all those records in a drop down or a formcould slow things down. If you only want to show current members you canfilter out anyone else and shorten up that list again, rather than deleting theinactive members and losing the history.

    1. Open CDClub.accdbfrom your desktop

    2. Click on the Createtab

    3. Then click Table

    Lesson5

    Lesson

    5

  • 8/12/2019 Access New Book

    46/170

  • 8/12/2019 Access New Book

    47/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 4 1

    Add MemberStatusID as a Numbertype in the new row

    2. Edit the Relationships

    UnderDatabase Tools, select Relationships

    Add the new table (tblMemberStatus) to the RelationshipWindow using the Show Table dialog box

    Link tblMemberStatus to tblMember using the MemberStatusIDfield

    Set Referential Integrity

    Close and Savethe relationship design changes

    Updated Relationships

  • 8/12/2019 Access New Book

    48/170

  • 8/12/2019 Access New Book

    49/170

  • 8/12/2019 Access New Book

    50/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    4 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Creating the Member Status type Entry Form

    From this point use the cdclubTablesdatabase from our class files folder.

    1. In the object navigation pane, click on tblMemberStatus(the tablename that is currently highlighted will be used for the source of theform).

    2. Select the Createtab

    3. In the Forms section, select the Multiple Itemsicon

    Types of Forms

    Single/Columnar Form: Displays one record at a time.

    Multiple Item/Continuous/Tabular Form: Displays as many recordsas will fit in the detail section of the form. As you type in one record,

    a new record is started below. The multiple items form is most oftenused for the lookup tables to create an easy form to maintain thevalues in those tables.

    This method of form creation automatically selects all fields from thetable and displays them on the form in Form View.

  • 8/12/2019 Access New Book

    51/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 4 5

    4. At this point the basic form is ready for data entry.Enter the followingvalues:

    Active

    Inactive

    Note how the icon to the left changes to a Pencil symbol and a new record iscreated below as soon as you start typing in the Member Status field. The

    primary key ID is also assigned at this point. The Pencil means this record iscurrently being edited. Once you leave that record, it is automatically saved,and it moves to the next record.

    5. Make note of what MemberStatusIDnumber gets assigned toActive, we will need that later in this exercise.

    6. We can edit this form in design view by selecting the Hometab, thenusing the view toggle button.

    Design view of a form

  • 8/12/2019 Access New Book

    52/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    4 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    When you open the form in design view initially it may show all the fields andlabels with an orange border. This means they are currently grouped together.To ungroup them, click anywhere in the form outside of the grouping.

    7. Edit the form title in the form header by clicking once to select thefield, then clicking again on the text of the field to go into edit mode.Remove tbl and put a space betweenMember and Status

    8. Remove the MemberStatusIDfield. This field does not need to be shownon the form.

    Select the field and hit Delete on your keyboard.

    Access automatically repositions the other fieldsafter you remove a field.

    9. Put spaces in the field names to separate the individual words in thelabels that are in the header section.

  • 8/12/2019 Access New Book

    53/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 4 7

    Important Note!

    You can edit the label (the transparent box), but you cannot edit thetext box (the white box). The text box is the actual field name that thedata entered will be saved into. If you change or delete the content in thewhite box, Access will not know where to save the data entered on the form.

    If you do accidentally change the field name, Access 2003 and laterwill mark the field and give you suggestions to fix the error. Forexample, if you change the MemberStatus field to Member Status,the field will show a green triangle in the upper left corner.

    Click on the triangle to produce a yellow exclamation sign. Click on

    it to see the Access tips for fixing the problem.

    The highlighted fields are the applicable errors. Listed below arepossible solutions. In this case, the solution would be to Edit theControls Control Source Property and choose the correct field (orsimply remove the space so it is a valid field name).

  • 8/12/2019 Access New Book

    54/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    4 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Locking the Field

    Because the Date Created is automatically filled in, and we would not wantsomeone to accidentally or purposely change it, we will lock that field frombeing edited.

    1. Right click on the DateCreatedField in the detail section of the formand choose PropertiesOR double click on the field

    2. On the Property SheetData tabchange Enabled to Noand Lockedto Yes

    Note about Enabled and Locked Properties

    The Enabled and Locked properties can be used together orindependently depending on the desired outcome.

    Enabled=No will lock and grey out the field

    Locked = Yes will lock the field but not grey it out. The field isselectable and can be copied. It can cause confusion on the endusers part because it acts like one should be able to type in the field

    Enabled=No AND Locked = Yes will lock the field but not grey itout and not allow a cursor into the field.

    3. Return to form view using the Viewtoggle to see the changes made.

    4. Close and Save the form as frmMemberStatus

  • 8/12/2019 Access New Book

    55/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 4 9

    Setting Active as the default Member Status

    If we want all new members to automatically be assigned an Activestatuswe can set the default property in the MemberStatusIDfield in tblMember.

    1. Open tblMember in design view

    2. Select the MemberStatusIDfield

    3. In the General tab, under Default Value, type in the number we wrotedown earlier as being assigned to the Active status.

    4. Close and save tblMember

  • 8/12/2019 Access New Book

    56/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    5 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Exercise 3: Creating Entry Forms Using Multiple

    Items Form Option

    Part 1:

    Performer entry form: We need to enter the performers ahead of time inorder for them to show up in combo box used to create a CD record. Thisform is used to add and edit the values in tblPerformer.

    1. In the Object Navigation pane, click on tblPerformer

    2. From the ribbon menu choose Create

    3. From the Forms section choose Multiple Items

  • 8/12/2019 Access New Book

    57/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 5 1

    4. Switch to Design View using the ViewToggle on the Home tab

    5. Edit the Label in the header of the form to remove the tbl

    6. Delete the PerformerIDfield

    7. Put spaces in the DateCreatedlabel

    8. Lock down the DateCreatedfield using the field properties (setEnabled to No and Locked to Yes)

    9. Save and name the form as frmPerformer

    10.Switch to Form Viewand enter test data:

    Enya

    Garth Brooks

    Green Day Ludwig van Beethoven

    Ralph Stanley

  • 8/12/2019 Access New Book

    58/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    5 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Part 2:

    Address Type entry form: We need to enter the Address Types ahead of

    time in order for them to show up in combo box used to create an Addressrecord. This form is used to add and edit the values in tblAddressType.

    1. In the Object Navigation pane, click on tblAddressType

    2. From the ribbon menu choose Create

    3. From the Forms section choose Multiple Items

    4. Switch to Design View using the ViewToggle on the Home ribbonmenu

    5. Edit the Label in the header of the form to remove the tbl and put a

    space between address and type

    6. Delete the AddressTypeIDfield

    7. Put appropriate spaces in the AddressType andDateCreatedlabels

  • 8/12/2019 Access New Book

    59/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 5 3

    8. Lock down the DateCreated field using the field properties (setEnabled to No and Locked to Yes)

    9. Save and name the form frmAddressType

    10.Switch to Form Viewand enter test data:

    Home

    Work

    School

    End of Exercise

  • 8/12/2019 Access New Book

    60/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    5 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Handling One-to-Many Relationships with Subforms

    A subform is a form within another form. A form-to-subform relationship

    can be defined as a parent/child relationship. A subform is the best methodof showing records from the table on the many side of the one-to-manyrelationship. For the record currently displayed in the main form, manyrecords can be shown on the subform. One example of this in our database isthe members and their addresses. We opted to allow multiple addresses foreach member. The main form shows one member from the member table,while the subform displays all of the address in the member address tableassociated with that members ID.

    Create a form to enter members with a subform to enter multiple addressesfor each member.

    Member Form

    The member form is the main form that shows one member record at a time.

    1. In the object navigation pane selecttblMember

    2. Choose the Createtab

  • 8/12/2019 Access New Book

    61/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 5 5

    3. Under the Forms section choose Form

    Newly created member form

    4. Go to the Hometab and Switch to Design View

    frmMember in Design View

  • 8/12/2019 Access New Book

    62/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    5 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    5. Click outside the field grouping to ungroup them

    6. Edit the top label in the header to read Members instead oftblMember

    7. Edit the field labelsto add spaces between the words

    Put a space between Member and ID

    We wont delete the key field in this case since the MemberIDcould be referenced and searched by within the database (likean account number)

    Put spaces between First, Middle, and Last and Name

    Put a space betweenDate and Created

    8. Replace MemberStatusIDwith a combo box that looks up the valuesfrom tblMemberStatus

    Select the MemberStatusIDfield and click delete

    From the DesignTab click on the Combo Box object to select it (itwill place an orange border around the selected object).

    Move your mouse to the location on the form that you want toplace the object, in this case - below the Date Created field. (Yourmouse icon will change to the icon for the object you haveselected).

  • 8/12/2019 Access New Book

    63/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 5 7

    The combo box wizard will appear, leave the default option, clickNext

    Select tblMemberStatusand click Next

    Move MemberStatusID and MemberStatusfields into theselected fields area by double clicking or using the >button, click next.

  • 8/12/2019 Access New Book

    64/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    5 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Note: When creating a combo box the Primary Key of the lookuptable should always be the first field and the text field the user willactually see and pick from should be the second field.

    Select MemberStatusas the field to sort by, click next

    The next screen is a preview of what the drop down boxcontents will be. Here you can make the column(s) wider ornarrower as needed. Note that the Primary key (the firstfield we selected) is automatically hidden from the user.

  • 8/12/2019 Access New Book

    65/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 5 9

    This step is critical, we must tell Access where to store theselection we make. The combo box stores the value of theprimary key which needs to be saved to the correspondingforeign key in the table the form is based on. Use thedropdown to select the matching foreign key fieldMemberStatusID, click next.

    Type in the text you want for the label part of the combobox: Member Status, click Finish

  • 8/12/2019 Access New Book

    66/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    6 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    9. Move the newly created combo box below the Birthdayfield. Accesswill automatically move the DateCreated field down to accommodatefor it and reformat the field to match the others.

    10.We need to shorten the fields to make room to add a subform. Groupall of the fields in the detail section

    Click anywhere above the MemberID Field (not the label, we dontwant the labels included in this grouping)

    Drag your mouse down and to the right until all fields are withinthe box it has created.

    11.Let go of the mouse and all the fields will be grouped and showingthe orange border

    Make sure that the labels to the left of the fields are not included in the grouping (not outlinedin orange)

    12.Hover over the right side and get the double arrow, then drag thegroup to the left to shorten all the fields at once.

  • 8/12/2019 Access New Book

    67/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 6 1

    13.Release your mouse around the 4 inch mark

    14.Lock down the DateCreatedfield by setting enabled to no and lockedto yes in the fields properties

    15.Closeand

    Savethe form as

    frmMember

  • 8/12/2019 Access New Book

    68/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    6 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Exercise 5: Creating a Subform using Autoform

    Member Address Subform

    Used to enter multiple addresses for a member once it is connected to themember form.

    1. In the object navigation pane select tblMemberAddress

    2. Choose the Createtab

    3. Under the Forms section choose Form

  • 8/12/2019 Access New Book

    69/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 6 3

    4. Go to the Home ribbon menu and Switch to Design View

    5. Click outside the field grouping to ungroup them

    6. Edit the top label in the header to read Addressesinstead oftblMemberAddress

    7. Delete the MemberAddressIDand MemberID fields

    8. Replace the AddressTypeID with a combo box

    Delete the AddressTypeIDfield

    Select the Combo Box option from the design tab and place itunder date created on the form

    Select tblAddressType

    Select AddressTypeIDand AddressType

    Sort by AddressType

    Store the value in AddressTypeID

    Type Address Typefor the label text

  • 8/12/2019 Access New Book

    70/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    6 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Move the newly created combo box above the Address1 field.

    9. Edit the field labelsto add spaces between the words

    Put spaces betweenAddress

    and the1

    ,2

    or3

    Put a space between Dateand Created

    10.Group all of the fields in the detail section

    Click anywhere above the AddressTypeID Field (not the label, wedont want the labels included in this grouping)

    Drag your mouse down and to the right until all fields are withinthe box it has created.

    11.Let go of the mouse and all the fields will be grouped and showingthe orange border

    Make sure that the labels to the left of the fields are not included in the grouping (not

    outlined in orange)

  • 8/12/2019 Access New Book

    71/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 6 5

    12.Hover over the right side and get the double arrow, then drag thegroup to the left to shorten all the fields at once.

    Release your mouse around the 3 inch mark

  • 8/12/2019 Access New Book

    72/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    6 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    13.Because this is a subform, we want it to be compact. We also need to shrinkthe size of the form itself (the area with the grid behind it). You may haveto scroll to the right to see the edge of the form.

    14.Hover over the right edge of the form and get the double arrow withthe vertical line.

    15.Drag the side of the form up to the right edge of the fields and release.

    Oops! It didnt work. The box for the addresses label is very large and needs tobe shrunk as well.

  • 8/12/2019 Access New Book

    73/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 6 7

    16.The easiest way to do that is to right click on the Addresses label in

    the header and choose SizeTo Fit

    17.Then repeat step 13.

  • 8/12/2019 Access New Book

    74/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    6 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    18.Lock down the DateCreatedfield by setting enabled to no and locked

    to yes in the fields properties

    19.Closeand Savethe form as subfrmMemberAddress (use thesubfrm prefex for all sub forms)

    Note:

    You should not enter an address in the subform as it is right now.

    You need to have it linked to the main form first to know whatmember the address belongs to. We will do that in the next steptogether.

    End of Exercise

  • 8/12/2019 Access New Book

    75/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 6 9

    Linking the Main form and Sub Form

    This step is similar to setting the relationship between two tables. We needto tell Access which primary key/foreign key fields link the two forms. Thismethod also allows Access to maintain the Primary and Foreign Key valuesthat are used to match the addresses with their respective members.

    1. Open frmMemberin Design View

    2. In the Designtab in the Controlssection click on Subform/Subreport

    3. Click in the detail area to the right of MemberID

    4. From the subform wizard click on Use an Existing Form

  • 8/12/2019 Access New Book

    76/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    7 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    5. Choose the subfrmMemberAddress formClick Next

    6. In the Define Link form, choose the Show tblMemberAddress for

    each record in tblMember using MemberIDoption Click Next

    If the show statement is cut off in the selection window you can seethe full statement right below.

  • 8/12/2019 Access New Book

    77/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 7 1

    7. Leave the name subfrmMemberAddressfor the form name ClickFinish

    8. Select the subfrmMemberAddresstext box created as a title for thesubform and press Delete on your keyboard.

    9. Savethe design changes to form.

    10.Switch to Form view

  • 8/12/2019 Access New Book

    78/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    7 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Navigating Records and Entering Test Data

    Navigating Records

    To move between records, use the navigation bar at the bottom of the form.

    First

    Previous

    Next

    Last

    New Record

    When you have a subform you will have a second set of navigation buttonsto move through the subform records.

    1=Main form, 2=Subform

    Entering Test Data

    1. Enter in your name and birth date in the main section of the Memberform

    2. In the addresses subform, choose Homeas the address type and enterin your home address

    3. Click on the Nextbutton in the subformsnavigation bar

    4. Choose Workor Schoolas the address type and enter another address

    for yourself

    5. Click on the Nextbutton of the main Members formand repeat foranother member. Enter a friend, relative, or made up member withtwo different addresses

  • 8/12/2019 Access New Book

    79/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 7 3

    Creating Forms using the wizard

    Genre Form

    This form will be used to enter values into the Genre Lookup Table for usewhen entering CDs.

    1. On the Create ribbon menu choose More FormsForm Wizard

    2. Choose tblGenre from the dropdown list

  • 8/12/2019 Access New Book

    80/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    7 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    3. Select the fields that you want to see on the form by using the >button.

    In this case we want Genre andDateCreated

    4. After the 2 fields are under the Selected Fields area, click Next

    5. Choose the Tabularoption (multiple items/continuous type of form),click Next

  • 8/12/2019 Access New Book

    81/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 7 5

    6. To make this form match our previously created forms choose theAccess 2007style, click Next

    7. Name the form frmGenreand click Finish

    8. From the Home menu, switch to Design View

    9.Remove frm from the

    frmGenrelabel

    10.Widen the Genrefield and label

    11.Lock down the DateCreatedfield by setting enabled to no and lockedto yes in the fields properties

    12.Save the design changes and switch back to Form view

  • 8/12/2019 Access New Book

    82/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    7 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Modify Formatting

    1. Enter test data:

    Country Rock

    Pop

    New Age

    J azz

    Classical

    Note the Alternating lines created with this style of creating a form.

    2. If we want to turn that off to match the style of the other forms we

    have created, go to design view and right click on the detail sectionbar

    3. Hover over Alternate Fill/Back Colorand select Noneto remove it.

  • 8/12/2019 Access New Book

    83/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 7 7

    Exercise 6: Creating the CD entry form using the

    Wizard

    1. On the Create tab choose More Forms

    Form Wizard

    2. Choose tblCDfrom the dropdown list

  • 8/12/2019 Access New Book

    84/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    7 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    3. Select the fields that you want to see on the form by using the >button.

    PerformerID

    GenreID

    Title

    YearReleased

    CDValue

    DateCreated

    4. After the desired fields are under the Selected Fields area, click Next

    5. Choose the (default)Columnaroption (Single form), click Next

  • 8/12/2019 Access New Book

    85/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 7 9

    6. To make this form match our previously created forms choose theAccess 2007style, click Next

    7. Name the form frmCD and click Finish

    8. From the Hometab, switch to design view

    9. Remove frm from the frmCD label

    10.Remove thePerformerID field and replace with a combo box Select PerformerIDand Performerfrom tblPerformer

    Sort by Performer

    Save selection to the PerformerID field

    Label as Performer

  • 8/12/2019 Access New Book

    86/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    8 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    11.Remove theGenreID field and replace with a combo box

    Select GenreIDand Genrefrom tblGenre

    Sort by Genre

    Store the selection in GenreID

    Label asGenre

    12.Space out the words in CDValue, YearReleased and DateCreatedlabels

    13.Lock down the DateCreatedfield by setting enabled to no and lockedto yes in the fields properties

    14.If you want to have the fields in a different order (more logical fordata entry), simply drag them up or down in design view. Move thetitle field to the top, followed by Performer, Genre, Year Released,Value and Date Created

    The other fields automatically adjust for you.

    15.Shorten all fields and the form itself so it is more compact but still has

    room in the fields for the data.

    16.Close andsavethe form

    End of Exercise

  • 8/12/2019 Access New Book

    87/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 8 1

    Adding to combo box lists on the fly

    1. Enter test data into frmCD:

    Title Performer Genre Year ValueA Day Without Rain Enya New Age 2004 $ 15.00American Idiot Green Day Pop 2004 $ 16.00Beethoven's Greatest Hits Ludwig van Beethoven Classical 1984 $ 12.00I Wonder Where You Are Tonight Del McCoury Bluegrass 2002 $ 15.00In Pieces Garth Brooks Country 2002 $ 15.00Kind of Blue Miles Davis Jazz 1991 $ 15.00Man of Constant Sorrow Ralph Stanley Bluegrass 2001 $ 15.00

    What happens if the Genre or Performer does not exist in

    the Combo Box?

    Answer: Starting with Access 2007 you will be prompted aboutadding the new value to the list

    Click Yes and the form you specified in the field properties will openup and you can go to a new record and add the missing value. Thevalue will be immediately available for use in the main form onceyou close the edit form.

  • 8/12/2019 Access New Book

    88/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    8 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    2. When you get to the first missing Performer (Del McCoury), hit esc acouple times to clear out the data entry

    3. Switch to design view

    4. Right click on the PerformerIDfield and choose Properties

    5. On the Datatab under List Items Edit Formchoose frmPerformerfrom the drop down list

    6. Close the properties window

    7. Repeat for the GenreIDfield, choosing frmGenre

    8. Continue with the data entry

  • 8/12/2019 Access New Book

    89/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 8 3

    9. Close and save the form

  • 8/12/2019 Access New Book

    90/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    8 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Finding a Record on a Form

    You can move through the records using the navigation bar at the bottom of

    the form in a small record set. Once you have a large amount of records,however, it is tedious to go through them one by one to find the record youneed. There are a number of ways to quickly locate a record or subset ofrecords on your form. Searching, filtering and using a search combo box willbe examined.

    Quick Search

    1. OpenfrmCDin Form View

    2. Click in the searchbox in the bottom navigation bar

    3. Start typing in a word that appears in any field on any record in theform.As you type the word the first record that has a match will bedisplayed. Ex. Where, or blue.Hit enter to move to the next matchingrecord if there are more.

  • 8/12/2019 Access New Book

    91/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 8 5

    Filtering by Selection

    1. Locate a record that has a Bluegrass CD

    2. Place your cursor in the Genrefield

    3. On the Home tab, in the Sort and Filter section, click on Selection

    4. Options will be displayed that will help you choose how to filter.Choose theEquals Bluegrass option

    5. The form will show that it is Filtered and how many records it foundthat matches the filter in the navigation area at the bottom of the form

    The form now only shows the 2 records that have a bluegrass Genre type.

    6. To remove the filter and see all records again click on Filtered and itwill change back to Unfiltered

  • 8/12/2019 Access New Book

    92/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    8 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Filtering by multiple items

    1. Click in the GenreField

    2. Choose Filterfrom the Sort and Filter section

    A Popup will display all the options for that field

    3. Clear all check boxes by unchecking the Select Alloption

    4. Select only Bluegrass and Jazz

    5.Click

    OK

    The records showing will be anything with Bluegrass OR Jazz genre types.

    6. To remove the filter, click on Filtered in the navigation area at thebottom of the form and it will change back to Unfiltered.

  • 8/12/2019 Access New Book

    93/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 8 7

    Using a Combo Box to Find Records on the Form

    If you want something more permanent and fewer steps than a filter, youcan add a Combo Box that will find a single record on the form for you. TheCombo Box can also be used to help avoid duplication of entries if you checkexisting values before adding a new record.

    7. Open frmCDin Design View

    8. From the Design menu Controls section click on the Combo boxicon

    9. Click in the form header section next to the CD label (leave enoughroom for the combo box label in between)

    10.From the Combo Box wizard, choose the third option Find a record

    on my form based on the value selected in my combo boxClickNext

  • 8/12/2019 Access New Book

    94/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    8 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    11.Add the CDID, Title, andYear Releasedfields to the Selected

    fields windowClick Next

    12.Expand the Title field Click Next

  • 8/12/2019 Access New Book

    95/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 8 9

    13.Name the Combo Box Find CDClick Finish

    14.Use the Font Size and Bold options on the toolbar to make the FindCD label Boldand 14 point

    15.Expand the width of the Combo Box and the label

    16.Switch to Form Viewand test the combo (lookup) box

    17.The list currently is not sorted, to make this function work better we

    need to sort by the CD Title (the field you would be typing a valuefor)

    Switch back to Design View

    Right click on the combo box and choose Properties

    On the Data Tabclick in the Row Sourcefield

    Click on the Ellipsis button at the end of the field

  • 8/12/2019 Access New Book

    96/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    9 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Choose Ascendingin the sort row under Title

    Close and Save the Query

    18.Switch to form view and search for a CD by typing in the start of aTitle or drop the list down and make a selection

    19.Save and closethe form

  • 8/12/2019 Access New Book

    97/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 9 1

    Creating the Member CD Form and Subform in Design

    View

    We will create the form and subform to track each members list of CDs thatthey own, and the loaning of those CDs to other members, from scratchusing design view.

    Creating the Member CD Main Form

    1. From the Createtab, in the forms section choose Form Design

  • 8/12/2019 Access New Book

    98/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    9 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    2. Click on Property Sheet

    3. On the Data Tab, use the drop down for Record Sourceto choosetblMember (the table this form needs to be based on)

    4. Close the Property Sheet

    5. From the Toolssection choose Add Existing Fields

  • 8/12/2019 Access New Book

    99/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 9 3

    The field list is divided into 3 sections: Fields from the table you chose as therecord source, fields from tables related directly to that table and the rest of thetables in the database. You can change the view to only show fields from thetable you selected by clicking on at the bottomof the field list.

  • 8/12/2019 Access New Book

    100/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    9 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    If you select records from a table other than your record source it will change tothe record source to a query joining the appropriate tables. This may produceundesired results.

    You can return to seeing all tables by clicking on Show all tables at the bottomof the field list.

    6. Select theFirstNamefield and drag it onto the form

    7. Drag LastNameonto the form to the right of FirstName

    8. Put spaces in the labels between the words

  • 8/12/2019 Access New Book

    101/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 9 5

    9. Closeand Savethe form as frmMemberCD (you will come back toit later to add a subform)

    Creating the Member CD Subform

    This form allows for all the CD titles owned by the member in the main formto be displayed or added to. It is also used to show if a CD is currently outon loan, to whom and when it was loaned out.

    1. From the Createmenu ribbon, in the forms section choose FormDesign

    2. From the Property Sheet choose tblMemberCDas the Record Source

    3. Create a Combo Box for the CD selection

    Base the combo box on tblCD

    Select the fields CDID, Title and YearReleased (in that order)

    Sort by Title

    Save the selection to the field CDID

    Label asCD

    Widen the field

  • 8/12/2019 Access New Book

    102/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    9 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    4. Create a combo box for the Loaned To field to the right of the CDfield

    Base the combo box on tblMember

    Select the fields MemberID, LastName and FirstName (in thatorder)

    Sort by LastName

    Save the selection to the fieldLoanedToID

    Label asLoaned To

    5. Click on Add Existing Fields

    Drag the DateOut field from the field list to the right of the Loaned Tofield

    6. Change the form to a Continuous Form (multiple item type of form)

    Click on the Property Sheetin the tools section

    Make sure the drop down says Form, if it is anything else changeit to Form

    Switch to the Format Tab

  • 8/12/2019 Access New Book

    103/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 9 7

    Use the dropdown to change the default viewfrom Single Form toContinuous Forms

    7. Close the properties window

    8. Shrink the form up from the bottom so it is just bigger than the fields(or it will leave a lot of white space in between each record)

    9. Close and save as subfrmMemberCD

    Link the main form to the subform

    1. Open frmMemberCD in design view

    2. Add subfrmMemberCDusing the Subformoption from the Controls

    3. In the subform Wizard, choose the existing form subfrmMemberCD

    4. Link the form and subform by the common key field MemberID

    5. Finish the subform wizard

    6. Back at the form design view, delete the label above the subform

    7. Expand the border of the subform downward to make room to showmultiple records

  • 8/12/2019 Access New Book

    104/170

    L E S S O N 6 :

    C R E A T I N G I N T E R F A C E S T O I N T E R A C T W I T H DA T A

    9 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    8. Savethe design changes and switch to form view

    9. Use the MemberCDform to loan a CD to another member in theclub, including filling in the Date Outfield. (If there are no othermembers listed in the Loaned to dropdown, add another memberthrough the Member form.)

    Did you notice?

    We chose two fields for the Loaned To Combo Box, but only one

    showed up after you chose the member.

    When you drop down the item, you will see all the fields, but onlythe first field after the Primary Key ID will display once selected.

    If you would rather see the first name instead of the last, recreate theCombo Box, choosing the Primary Key first and then FirstNamefollowed by LastName.

  • 8/12/2019 Access New Book

    105/170

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 9 9

    Date picker

    The date picker is a new feature to Access 2007, it is a popup calendar you

    can use to enter a date into a field instead of manually typing in thenumbers. The icon will show on forms and reports next to a date fieldcurrently being edited. It also has a handy Today button at the bottom toeasily select the current date.

    The Date Picker will not be available if there is an input mask on the datefield. That is the case with our Date Out field. If we want to use the calendarto select a date for this field we have to go back to the table and remove theInput mask from the field.

    1. OpentblMemberCD in design view

    2. Select the DateOutfield

    3. On the Generaltab, clear out the value in the Input Mask

    4. Close and save the table design changes

    5. Try it out on the form

  • 8/12/2019 Access New Book

    106/170

  • 8/12/2019 Access New Book

    107/170

    U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r 1 0 1

    Editing a Form

    The Member CD form and subform we created in design view do not matchthe style of the forms we created using the automated tools. We can edit that

    form and assign a format to it and add a label in the header.

    Modifying a Form

    1. OpenfrmMemberCDin Design View

    2. Go to the Arrangetab

    3. In the Show/Hidesection choose Form Header/Footer

    New form header section has been added

    Lesson7

    Lesson

    7

  • 8/12/2019 Access New Book

    108/170

    L E S S O N 7 :

    E D I T I N G A F O R M

    1 0 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    4. From the Arrange tab choose Autoformat

    5. Choose the Access 2007format that we used in the prior exercises (ifyou hover over the thumbnail it will give you the format name, it isthe second one in the first row)

    6. Expand the form header section downward

    7. Switch back to the Designtab and select Label

    8. Drop the label in the header and type in Member CD List

  • 8/12/2019 Access New Book

    109/170

    L E S S O N 7 :

    E D I T I N G A F O R M

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 0 3

    9. Change the font and size to the following:

    10.Right click on the label and choose Sizeto Fit

    We should also lock out both the first name and last name fields from beingedited. Members should only be added through the Member Form.

    11.Select both fields at the same time by holding down your shiftkey.

    12.Click on Property sheeton the Design tab

    13.Set Locked to Yes on the Data Tabof the Property sheet

    If you set both Enabled to No and Locked to Yes, you will not be able tosearch on that field

    14.Closeand Savethe design changes

  • 8/12/2019 Access New Book

    110/170

  • 8/12/2019 Access New Book

    111/170

    U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r 1 0 5

    Queries

    From this point use the CDClubFormsdatabase.

    After data has been entered using the forms, you can use queries to ask

    questions of your database. You can view and analyze fields from one tableor join multiple tables together. A common reason for creating a Query issimply to join tables together to view related content. Queries are generallythe basis of reports as well. Use the query to pull the fields and narrowdown to the records desired, the report just formats the data for printing.

    Creating a Query using the Query Wizard

    CD List with Owners

    The goal of this query is to create a master list of all CDs that are owned bythe members and who owns them. We need to pull information from severaltables to include all the fields needed for the query results.

    1. On the Create tab choose Query Wizard

    2. Leave at the default of Simple Query Wizard, click OK

    Lesson8

    Lesson

    8

  • 8/12/2019 Access New Book

    112/170

    L E S S O N 8 :

    Q U E R I E S

    1 0 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    3. In the Tables/Queries dropdown select tblCD

    4. Add Titleand YearReleasedfields to the selected fields area

    5. Switch to tblGenre

    6. Add the Genrefield to the selected fields

    7. Switch to tblPerformer

    8. Add the Performerfield to the selected fields

    9. Switch to tblMember

  • 8/12/2019 Access New Book

    113/170

    L E S S O N 8 :

    Q U E R I E S

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 0 7

    10.Add the FirstNameand LastName fields to the selected fields

    11.Click Next

    OOPS!

    In order for Access to know how these tables are related, and to pullfields from several tables in this query wizard, the tables have to beset up in the relationship design. In this version of the database, onerelationship has been left out.

    12.Click OKand it will show the relationships window

    13.Closethe show table dialog box

    14.Recreate the missing relationship between tblGenreand tblCD

  • 8/12/2019 Access New Book

    114/170

    L E S S O N 8 :

    Q U E R I E S

    1 0 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Dont forget to set Referential Integrity

    15.Closethe relationship window and start over at Step 1 of this Exercise

    16.Leave the default of Detailand click Next

    17.Save the Query as qryC DListWithOwners

  • 8/12/2019 Access New Book

    115/170

    L E S S O N 8 :

    Q U E R I E S

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 0 9

    Be descriptive in the query and report names, you may endup with several that are similar and you will want to be ableto easily identify the purpose of the query or report just bylooking at the name of it.

    The query initially opens showing the results in query view

    Modify a Query Using Design View

    1. Switch to Design View using the view toggle

  • 8/12/2019 Access New Book

    116/170

    L E S S O N 8 :

    Q U E R I E S

    1 1 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Did you Notice?

    tblMemberCD is included in the query even though we did not

    select any fields from that table.

    We cannot make a connection directly from tblCD to tblMember.When we set up the relationships, we told Access thattblMemberCD is needed to join the two tables, so Accessautomatically added tblMemberCD into the query design.

    2. Add a new field to the query to combine the Last and First Namefields into one field called Owner. This field exists only within thisquery

    In the next blank column, type Owner:

    The colon signifies that this is a new field name)

    After the colon type LastName &, & FirstName .

    The , [space] between the fields leaves a comma and a spacebetween the values so they do not run together)

    Once you tab off the field, Access will add [ ] around each fieldname.

    If you are working in a database that has spaces in the field

    names, you must put in the brackets manually, or Access willsee each word as a field

    3. Delete the original Name fields by hovering above the FirstNamecolumn until you get a downward pointing arrow.

    Drag across to the Lastnamecolumn so both are highlighted.

    Then hit the Deletekey

  • 8/12/2019 Access New Book

    117/170

    L E S S O N 8 :

    Q U E R I E S

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 1 1

    4. View the query results. Note that the new column name is the name wegave the field.

    5. Closeand Savethe Query design changes

    Queries are dynamic, meaning as the data changes, the query results willchange. If you query for a list of all the CDs in the club database today, andthen again in a month, any CDs added, edited, or removed in the next monthwill change the query results. If Prince changes his name, for example, it will bereflected in the new results.

    6. Open the Performerform

    7. Find the record for Prince

    8. Change the value from Prince to Artist Formerly Known as Prince

    9. Double click on qryCDListWithOwners to run the query

    Note the name change is reflected in multiple records even though

    you only changed it once

    Before

    After

  • 8/12/2019 Access New Book

    118/170

    L E S S O N 8 :

    Q U E R I E S

    1 1 2 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Exercise 7: Creating a Query Using the Wizard

    CD Master List

    The CD List with Owners query shows multiple records for some CDs. Thisis because more than one Member owns that CD. We avoid having the CDinformation stored in the table multiple times by setting up the properrelational database structure, but we display it for every instance in thequery results. To see just a unique list of all available CDs in the club dontinclude anything from the Member table.

    1. In the Query objects, click on Create Query using Wizard

    2. Pull fields from tblCD

    Title

    CDValue

    YearReleased

    3. Switch to tblGenreand add the Genrefield

    4. Switch to tblPerformerand add the Performer fieldClick Next

    5. Leave the default of DetailClick Next

    6. Name it qryCDMasterList

    7. Click Finishand the Query will open showing the results

  • 8/12/2019 Access New Book

    119/170

    L E S S O N 8 :

    Q U E R I E S

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 1 3

    Add a Sort to a Query

    It might be hard to tell at this point that there is only one record per CD, sowe can add a sort to the query.

    1. Switch to Design View

    2. In the Title column Sort row, choose Ascendingfrom the drop down

    3. Switch back to the query results view. Now the CDs will be in orderby Title

    End of Exercise

  • 8/12/2019 Access New Book

    120/170

    L E S S O N 8 :

    Q U E R I E S

    1 1 4 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Adding Criteria to a Query

    Criteria are used to restrict or narrow down which records are returned in

    the query. The results of using criteria on a query is similar to filtering on aform.

    1. In the Queries objects window, right click on qryCDMasterList

    2. Choose Copy

    3. Right click again and choosePaste

    4. Name the new query qryCDMasterWithCriteria

    5. Open the new query in Design View

    6. In the Criteria row under Genre, type Bluegrass

    Access will add quotation marks around all text fields

    Criteria must be spelled exactly as it appears in the data

    7. Switch to Query ResultsView

    Only CDs with the Bluegrass genre will appear

    8. Return to Design View

  • 8/12/2019 Access New Book

    121/170

  • 8/12/2019 Access New Book

    122/170

    L E S S O N 8 :

    Q U E R I E S

    1 1 6 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Creating a Query in Design View

    CDs on Loan Query

    Create a query in Design View that displays onlyCDs out on Loan.

    1. On the Create tab, under the Other section click onDesign View

    2. From the Show Table dialog box add the following tables: tblMember

    tblMemberCD

    tblCD

    tblPerformer

    3. Closethe Show Table Dialog box

    4. Add the following fields by dragging them into the query design grid

    From tblMember:

    FirstName

    LastName

    From tblCD:

    Title

    From tblPerformer:

    Performer

  • 8/12/2019 Access New Book

    123/170

    L E S S O N 8 :

    Q U E R I E S

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 1 7

    FromtblMemberCD:

    LoanedToID

    DateOut

    5. Viewthe query results

    The results include ALL CDs. Add criteria to check if there is a value in DateOut in order toreturn only those CDs out on loan

    6. Return to Design View

    7. In the DateOut Criteria row type is not null. Null is equivalent to blankor empty.

    8. Viewthe query results again

    Only CDs currently on loan will be returned

  • 8/12/2019 Access New Book

    124/170

    L E S S O N 8 :

    Q U E R I E S

    1 1 8 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    Replacing the Loaned to Key with the Member Name

    Lastly, we will want to replace LoanedToID with the actual Members namethat has the cd out on loan.

    1. Switch back to Design View

    2. Using Show Table, Add tblMemberto the Design View a second timeso we can link it to LoanedToID. It will be called tblMember_1 sincetblMember is already in the query.

    3. LinkMemberIDin tblMember_1 to LoanedToIDin tblMemberCD

    4. Delete LoanedToIDfrom the query design grid

    5. Replace it withLastNamefrom tblMember_1

    6. Add Lent To:in front of the LastNamefield you just added todifferentiate it from the Lender

    7. View the query results

    8. Close andSavethe query as qryCDOnLoan

  • 8/12/2019 Access New Book

    125/170

    L E S S O N 8 :

    Q U E R I E S

    U n i v e r s i t y T e c h n o l o g y Tr a i n i n g C en t e r 1 1 9

    Exercise 8: Creating a Query in Design View

    Member Directory

    Create a query that displays all the members and all their addresses in thedatabase.

    1. On the Createtab, under the Othersection click onQuery Design

    2. From the show table dialog box add tblMember, tblMemberAddress,and tblAddress Type

    3. Add the Name fieldsfrom tblMember

    4. Add AddressTypefrom tblAddressType

    5. From tblMemberAddressadd the fields from Address1thru Email

    6. Sort Ascendingby the MembersLast Name

  • 8/12/2019 Access New Book

    126/170

    L E S S O N 8 :

    Q U E R I E S

    1 2 0 U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r

    7. View the query results, you should have 22 records

    Notice that you have more than one record for some Members. Even though they are only in thedatabase once, they have more than one Address in the table. When you join the tables, it finds all thematches and displays them.

    8. Close and Save as qryMemberAddress

    End of Exercise

  • 8/12/2019 Access New Book

    127/170

    U n i v e r s i t y T e c h n o l o g y T r a i n i n g C e n t e r 1 2 1