ACADEMIC TECHNOLOGY SUPPORT Microsoft Access 2013 ats@etsu.edu | 439-8611 www.etsu.edu/ats TABLE OF CONTENTS Getting Started .......................................................................................................... 1 Navigation Pane................................................................................................... 7 Data Types............................................................................................................ 2 Table ...................................................................................................................... 3 Table Editing ........................................................................................................ 3 Quick Forms ............................................................................................................. 4 Navigation Form ................................................................................................. 8 Report Creation ........................................................................................................ 4 Filtering and Sorting............................................................................................ 6 MS Access Forms ..................................................................................................... 7 Form Creation Methods ..................................................................................... 8 Using a Form for Navigation........................................................................... 13 Creation of Reports ........................................................................................... 14 Creations of Queries ......................................................................................... 14 Relationships ........................................................................................................... 16 Overview Microsoft Access Part I is an instructor lead, hands-on, small group, interactive workshop. Templates, support material, and an opportunity to ‘See and Try’ is the guiding methodology of this workshop. Participant experiences and Objectives will include how to: Create a database table Open and Edit database objects Assign data types Edit a Table Add Navigation Form Create a quick form Create a report Participants will successfully create and produce five out of seven of the Objectives with verbal guidance in the last 20 minutes of the workshop. Microsoft Office Access II is an instructor lead, hands-on, small group, interactive workshop. Templates, support material, and an opportunity to ‘See and Try’ is the guiding methodology of this workshop. Participant experiences will include: Creation of Access Forms Using a Form for Navigation Creation of Reports Relationships in Access This session is devoted to Best Practices in Collecting Data and in Sharing Data in Access. Microsoft Access Part III is an instructor lead, hands-on, small group, interactive workshop. Templates, support material, and an opportunity to ‘See and Try’ is the guiding methodology of this workshop. Participant experiences will include: Objectives: 1. Participants will take a look at the justification for creating a relationship in Access. 2. Participants will learn to create a Many to One and Many to Many relationship. 3. Participants will learn to create inner and outer JOINS. This session is devoted to advanced Relationships in Access, Review of Tables and Reports from Queries and to the ways they make Access a better application to collect data. Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 1 2 Part I Getting Started Information from Microsoft http://office.microsoft.com/en-us/access-help/basic-tasks-for-an-access-2013-desktop-databaseHA102809525.aspx Working with a Database can be intimidating. Databases expect Strict Rules and predesigned Structure. Most folk’s experience with an Access Database is from the data entry side. An advanced skilled person creates the Access Database and Users enter the data in form fields. Why use a Database instead of a Spreadsheet? 1. You have too many separate files or too much data in individual files. 2. You have multiple uses for the data that you are collecting. 3. You need to share the data with others or need to quickly sort the data. 4. You must control the data and make sure it is correct in all places throughout the data collection objects. A Database is a collection of persons, places, and things. It may contain numbers and other figures. Access Databases contain objects such as Tables, Queries, Forms, and Reports. This session will focus on a basic database and simple form. Creating a Table Select Blank Desktop Database Type a File Name (I suggest no spaces between words) Select where it will be stored and make a mental note of where it will be located Click the CREATE button Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 1 Tables Tables are the foundation of all databases. Tables are created by using a working view called Design View. Each column fieldname will be entered vertically in design view. Under the Field Name heading, insert a simple Field Name without spaces. Select a data type: text, number, hyperlink, etc. Enter a short description related to the field name. Remember the Fields are the column titles. Each Table is given an ID. Think of it as a reference number. The ID is not used to keep track of the number of records collected. The database collects characteristics about this item, person, place, or thing. The collector will need to know name, price, when, what, where, color, condition etc. A table can be edited in Design View (best practice) and now in Access 2010 and 2013 in Datasheet View. HAVING said this, the newest way to create a Table is as follows in Datasheet View: Open a Database, Go to Create Table or begin with the new Table that appears when the Database opens. First Column is the ID Next “Click to Add” Type in Name Click to Add Type in XXX Continue To move from column to column use the TAB. Edit the Column Names by clicking Field1 and enter the field name. Try to keep it short and no spaces. Save the table by Ctrl+S or you can save by Alt, F, S. Data Types http://office.microsoft.com/en-us/access-help/introduction-to-tablesHA102749616.aspx?CTT=5&origin=HA102809525 The basic Data Types are Text, Numbers, and Dates. Data type numbers are anything that can be added, subtracted etc. Numbers can also be identifying IDs. Fields of all types can be moved. New fields can be added at the end of the columns or in the middle. Fields are by clicking in the gray square at the top of the column and dragging to a new location. Once a field has been selected, it turns gray and can be moved or deleted. A Field data type change or deletion loses all its data. To be safe, it might be better to leave a data field as is and create a new one to take its place should needs change. The old Field can be hidden and in the description area with a detailed justification on why it is no longer used. 2 Complete List of Data Types Short Text: The default for text is a field size of 255. Long Text: Long Text is a collection of a large amount of text in a field. Number: Number can be used for a 'Foreign Key' - that is when two tables are being linked - there must be a field that connect them and of course number type is used when the entry is contains numbers that can be added or used in a formula. Date/Time: Access recognizes date and time as such. It makes it helpful when setting up queries. Currency: Formats as currency that allows for adding and formulas in queries and keeps the decimal to two positions. AutoNumber: Auto Number is the primary key field. Auto Number input assures that no two records will have the same ID Number. Yes/No: This data type shows as a check box on a form or datasheet. Ole/Object: Can be almost anything you want to collect. This object can be images, pictures, spreadsheets, or documents. Hyperlink: Data entered is a URL or Email address. It will take on the format of an active link. Attachment: The attachment feature allows documents, spreadsheets etc. be attached for download and storage. Calculated: Data used for entering formulas and number values. Lookup Wizard: Data type can be an associated table or a list of items. This can ensure that only items listed can be selected or you can modify properties so an item can be entered that is not on the list. Table http://office.microsoft.com/en-us/access-help/introduction-to-tablesHA102749616.aspx?CTT=5&origin=HA102809525 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. Open Access 2013 Go to File > Backstage Blank database Give the Table that appears a name (change it from Table 1 – try to keep it simple) Save the database To add a Table…..Open the database OR if it is still open go to… Create Table Name the Table To add a Table by Importing or Linking Go to the External Data Top Import & Link Group Follow the prompts Table Editing http://office.microsoft.com/en-us/access-help/introduction-to-tablesHA102749616.aspx?CTT=5&origin=HA102809525 Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 3 Did you name the table? If not, name the table by right clicking on it and selecting rename. Congratulations for successfully making an Access Database. Editing a value is simple, tab to the field/cell and change the data. Add a new row/record by moving to bottom of data and start typing. Delete a row by right clicking in the margin and selecting delete. Keep in mind, ACCESS does NOT have an UNDO. Handy ShortCut Keystrokes. http://office.microsoft.com/en-us/access-help/keyboard-shortcutsHP003089886.aspx Make Backups by going to File Tab and Saving Database as XXX… Also the User can go to File and Backstage. The database can be copied and pasted with another name. It is most important to make a backup often of the database. When an Access Database is Open, it creates a .laccdb file. This file locks the database from others while it is edited. Saving as older file types can remove new features so beware. The New file type is .aacdb; the older file type was .mdb Databases can become large as time goes on. A Database can be tweaked so it becomes more compact and actually works more efficiently. The method to reduce a bloated database is to compact it. Compacting can be automated or manual. To automatically compact Choose File, Options and Select the Current Database. Turn on Compact on Close and check OK. Tip: An Access Database can be transferred from location to location using Skydrive. A user cannot use an Access Database from Skydrive. You would have to use the Web Based Access Database in order to keep it on SkyDrive AND it requires SharePoint. For more information about SkyDrive go to http://tinyurl.com/skydr Quick Forms An added feature to make it easier to enter data is to add a form. Forms will be discussed in the next Access Session Part II, but to make a simple quick form, select the table that needs a form and Go to the Create Tab. Select Form and magically a form appears. The form is connected to the Table as a means to enter data. Note that the form can be deleted without deleting data in the Table. The Table(s) is the main Object in the Database. Query 4 Open Access Create, Other, Query Wizard Simple Query Wizard Add fields that will be needed Next Details Next Summary – IF numbers were included Finish and Run the Query http://office.microsoft.com/en-us/access-help/introduction-to-queriesHA010209892.aspx?CTT=5&origin=HA010285100 A query can be saved, modified in Access Query Design View, and modified with a different name. Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 5 Report Creation Create a Report in the same method for creating a Form. Select the Table with data and go to Create Report. Edit the look of the Report by going to Design View. An Access Database need not be intimidating. Start small with things you already know and then expand. I hope to see you in the Part II Session. Filtering and Sorting Steps to a Quick Filter 6 Select the Column with data Click the dropdown at the column’s head Clear all the checkmarks and recheck the items you want OK Quick Filters will select Equals, Does Not Equal etc. IF the column contains numbers, the filter options will include Custom Filter Options. Filter by Form enables filtering by more than one field. In the Sort and Filter group select Advanced and by Form A blank datasheet appears Enter search criteria in one or more fields Select the Toggle Filter command Click the Toggle Filter again it will display all records that meet the criteria (if any is entered in the fields) Remove the Filter by clicking on the field heading and select Clear Filter From…. Filters are a momentary function. When the same or similar question is asked often of an Access Database, instead create a Query. Navigation Pane The Navigation Pane is located on the left side of the screen. It can be collapsed. It can be arranged to meet your needs. Objects can be hidden or shown. Objects can be arranged in several ways. To Change the width of the Navigation Pane, hover the mouse pointer over the right edge and when the mouse pointer turns to a double-sided arrow, click and drag the edge To Expand or Collapse the Navation Pane use the ‘Shutter Bar” Go to Tables and Related View to sorts all objects by type Go to Created Date and Modified Date to show objects from a selected date Go to the top of the Navigation Pane ‘View By’ Details, Icons, or List Users can Create and Modify Custom Categories and Groups, great for quick access of select objects or for hiding objects Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 7 Navigation Form http://office.microsoft.com/en-us/access-help/create-a-navigation-formHA102749225.aspx?CTT=1#_Toc257200042 1. 2. 3. 4. Go to the Create Tab Go to the Forms group and select Navigation and Style Go to View and change the View type to Layout Add objects to the Navigation by dragging to the Add New Tab Part II MS Access Forms A form in Access is a softer, less intimidating object in Access. It has the purpose of collecting data or viewing data in a way that is user friendly and safe. An Access form can be modified and deleted without damaging or removing data from the collection Tables. The data collected will be fed into Tables that look and act much like an Excel Spreadsheet. You can create several forms, with various fields, all feeding into one database table. You can use forms to control user input to selected fields that might have confidential data. In this way the creator can provide input users or data collectors with a form that contains selected fields. Form Creation Methods (Prerequisite - What comes first the form or the table? The correct answer is a Table to collect the form data. Select the Create Tab. Select a Table in your database. Select the Form icon to create a simple form. If you have a table selected and select the Form Icon, a form will magically appear. Sometimes the fields are not positioned to your liking. If you want more control, select Form Design under the Create Tab/Forms Group. You can create a Form by starting with Form Design. Under the Create Tab/Forms Group select Form Design. A Form in Design View will appear on the screen. It looks like the image below. 8 Go to the Forms Design Tools on the Ribbon and the Tools Group and select Add Existing Fields. The Field List displays all Tables and Fields. If you see a plus to the left of a Table name, select the plus to expand the list of Table Fields. Select a Field and drag it to the form. After the fields are placed in the Design Form, align and space them. Start at the top of the form just above the first field and insert your cursor. Drag to surround all the fields or just the fields you want to align. Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 9 Release the mouse. If you were able to select all the fields, each field will display orange borders. Go to the Arrange Tab. In the Sizing & Ordering Group select Size/Space. Make all Fields the same size if desired. Go to the Align Command. Select Fields or Field Names and the appropriate Button to align perfectly to the left or to the right. If you want to control the form by inserting only the fields you want but allowing Access to align them, try the Form Wizard also found under the Create Tab/Form Group and select Form Wizard. A dialog box appears. Look for the drop down called Tables/Queries. Locate the Table to associate with the form. The bottom left column will be the available fields. Use the Greater-Than icons in the center to move fields from the left side to the right side. Follow the prompts until you come to Finish. Select Finish to see your form. 10 If you use the Blank Form Command a Blank White empty form appears. Fields can be added to the Blank Form from the 'Add Existing Fields' found on the Create Tab in the upper right corner. The Blank Form option behaves like the Design Form but may be less intimidating because Access attempts to align and group for you as you drag fields to the Blank Form. Notice the Controls that become available when using the Blank Form. You can also drag from the Controls Group to add Text Labels, Buttons, Links, Images and other Advanced Controls such as ComboBoxes and Pages. Use the Text Box (ab|) by selecting it and dragging a box on the form. Select the Text Box and type a title. In the Design Tab look for the Header / Footer Group. In the Header / Footer Group the Title Command is available. Other options are Logo, Title and Date and Time. Select a Command and double click or Click and Drag a Command while in Design View or while in Blank Form View. Try adding a Title from the Header/Footer Group. Double click the Title icon. Type inside the Text Box. Select the Logo Command to add a Logo by using an image on your computer. Add Page Numbers, Date and Time if desired. Other Tools under the Arrange Tab Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 11 Under the Arrange Tab look for the Table Group. Select some Fields and Change the layout to Tabular. Watch the change in position/layout. Tabular changes the layout vertically. Stacked produces the typical Horizontal look we generally think of on a form. Under the Arrange Tab/Position Group look for Control Padding. This inserts more or less space between labels and fields. Control Margins push the label and field against or away from the box holding the data and the Anchoring Command modifies the position of the Field and its associated label (name). 12 Test the New Form I always test a new form but it is annoying to tab back and forth to make sure data is really being submitted to the table. Instead, go to the Forms Group and select More Forms and Split. Now you can see the form and the table in the same window. Add some data to the form and watch the table. DO NOT forget to Refresh or the data will not show. Test to make sure the form is really feeding to the table. Add Form Fields to an Established Form First, you must add a new Field to a Table in your database (we covered that in the Tables Guide). Now go to your Established Form. Open in Design View by Going the Create Tab/Forms Group and Design View. In the upper right of your screen, select Add Existing Fields. Existing available Fields will display. Select and drag a Field to your form. Test your form to be sure it is still working. Now that your form is functional and beautiful, we want this form to be the first thing that users see. Displaying the Form Go to the upper left corner of the screen. Select the File Tab (in 2010 & 13 - instead use the Office Button in 2007). Next, open Access Options. Give your application a title. Find an icon and select the form you want folks to see when they first open this database. Using a Form for Navigation Once upon a time, we used something called a Switchboard to Navigate through all the objects in an Access Database. Beginning in MS Access 2007 it was suggested that we use a Navigation Form. In MS Access 2013 it is suggested to use the Navigation Pane to navigate or create a Navigation Form. Go to the Create Tab. In the Forms Group select Navigation Form. You have several template styles to pick from. Select Vertical Navigation. Drag a Form from the "All Access Objects" column on the far left side of the database window to the "Add New" button in the Navigation Form. This column shows objects in this database. Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 13 If you have several Forms or other objects, they can be added by dragging from the left side Navigation Column to the Navigation Form Add New Button. We can modify the look of Buttons by going into Design Mode. In the Form Design Tool Tab, go to the Format option. You can change the Button to a picture, a Caption with a Picture or you can change the Shape, Shape Effects, or Position of the Button. In the Form Design Tools you can truly make the form unique. The Navigation Form behaves and are edited much like other Forms in the Database. In Summary We can make a simple table in Access, and create a snappy form with awesome navigation. Using the Navigation Form to show off your database is much easier than the old switchboard that we all loved to use but hated to create. Creation of Reports http://office.microsoft.com/en-us/access-help/introduction-to-reports-in-accessHA102749545.aspx?CTT=1 The source of a Report can be a table or query. Select the Report Tool based on the author’s expertise. Select a Report, Report Design, Report Wizard or Labels. Create and Finish. Tweak and modify using the Design View. Details related to modifying a Report can be found http://office.microsoft.com/en-us/accesshelp/introduction-to-reports-in-access-HA102749545.aspx?CTT=1 Creations of Queries http://office.microsoft.com/en-us/access-help/course-summary-use-criteria-in-your-access-2013-queriesHA104102106.aspx What is a query? We have already talked about sorting. Sorting is a temporary method to retrieve information from a database. It is likely that a monthly report may be needed and therefore it is easier to say a query to be 14 used over and over. Each time the query is run it will pull new and old information. It will pull out exactly what you ask it to retrieve from the table or tables. To create a query go to Create > Query Wizard > Select the Table that holds the information and drag from left to right the necessary fields for this particular query. Go to Design View and add the criteria to the Criteria Row. Some basic rules are to always surround text criteria with double quotes. Don’t put anything around numbers. Surround Dates and Times with pound signs. To retrieve AND information put it on the same line. To retrieve OR information put the criteria on a different row. NOT, IN, LIKE, BETWEEN are so useful in that NOT returns all the data that is not in your critieria. In returns all the data that IS in your criteria. Like returns data along with WildCards in case you do not have the exact spelling etc. Between returns data between two dates and times. http://office.microsoft.com/en-us/access-help/apply-criteria-to-a-query-HA102836326.aspx Examples of Criteria for Text Fields, Number, and Currency Fields http://office.microsoft.com/enus/access-help/examples-of-query-criteria-HA102815718.aspx?CTT=5&origin=HA102836326 The Query Type I have been talking about up to now is Select Queries. Another type of Query used often is an Action Query. The Action Query can create a new Table, Add Data to a Table, Find and Replace Data, Create Totals, Update to new Information and Scary as it may be, it can also Delete Information. Parameter Query is type of query that can ask for the data each time it is run. For example, a query that is created to pull all the names of students from Tennessee can be created as a Parameter Query so the user can also ask for all the students from California. Go to Design View > In the Criteria row type the following [For What State]. Next time the query is run it will ask for the state input. A Totals Query might be something like this…Create > Query Design > Insert Column > Right Click the Field Row > Select Zoom on the Menu and type in the Formula >Run. Last Query in this handout is the Duplicate Records Query. Go to Create > Query Design > Show Table and select the Table needed. Add the Fields that you will use to determine this is a duplicate, such as same First Name and Last Name. Run the Query and click Delete. Make sure that the Delete row in the * columns displays From and Where and that this is really what you want to do. Run and select Yes. Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 15 Part III Relationships So far in Access we have created lonely tables that collect information. For example, our office needs to keep a list of classes our students are taking. We need to monitor their progress. We need to make sure they have completed X number of classes successfully within a predetermined time. In a well designed database we will have many tables and each table will be manageable. A well designed database eliminates redundancy. In our example, our tables will remain ‘pure’ to the specific content within them. Tables needed to collect the data for this example: Students table o StudentID (Primary Key) o StudentE o First Name o Last Name o Address o City o State o ZIP o Phone o Email o Date Entered Program o Date Exited Program Classes in Program o ClassesID o Class 1 o Class 2 o Class 3 o Class 4 o Class 5 o Class 6 o Class 7 o Class 8 o Class 9 o Class 10 o Class 11 o Class 12 o Exit Exam Instructors o InstructorsID o Instructor 1 o Instructor 2 o Instructor 3 o Instructor 4 Linking Tables to create Relationships In this example, the Student Table is the Parent Table because our focus is all about the students. We will create a One Student to Many Classes. The same applies to the Instructor student relationship. We will have One Student with more than one Instructor. 16 Students table o StudentID (Primary Key) o StudentE o First Name o Last Name o Address o City o State o ZIP o Phone o Email o Date Entered Program o Date Exited Program Classes in Program o ClassesID o Class 1 o Class 2 o Class 3 o Class 4 o Class 5 o Class 6 o Class 7 o Class 8 o Class 9 o Class 10 o Class 11 o Class 12 o Exit Exam o StudentID (Foreign Key) Instructors o InstructorsID o Instructor 1 o Instructor 2 o Instructor 3 o Instructor 4 o StudentID (Foreign Key) OR we could use a dropdown to achieve a similar relationship. The Relationship for a dropdown looks like this: Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 17 Points about relationships A relationship links two fields that are in different tables. It POINTS to the two or more items that are connected to each other. Another way to say it is that the Link connects a Parent to a Child. IF we Enforce Referential Integrity, the Child MUST have a parent and they can not be orphaned. On the left side is the Parent…on the right side is the Child. SOMETIMES a database requires more tables and information. As a database grows, we may need to create something called a many to many relationship. In our example, we were focused on the students in our program. Now it is important to enter data related to our instructors also. 1) We need a table with all our students 2) We need a table with all our instructors 3) We need a table with all our classes As you see we already had that before, but now our focus may be on our instructors or it may be on our classes or it may be on our students. 18 Students take classes. Instructors teach classes. We need a relationship between students and classes and a relationship between instructors and classes. This would give us a one to many relationship between students and classes and a one to many relationship between instructors and classes and to completely complicate things…classes will have more than one student, instructors will have more than one student, students will have more than one class and students will have more than one instructor and it goes on. To enable all these relationships we can create JUNCTION Tables. The junction table would be like this: Currently we have the Details about each class contained in the Classes Table. Classes will the offered each semester over and over. The details will remain the same. To remove the redundancy, we will create another table for classes descriptions. It can the linked and used over and over even when the class CRN changes to reflect the new course offering. Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 19 A Database with junction tables are the most complete and useful for collecting detailed information. Entering the information in each table is easy but adding the ID numbers in the Junction Table may be tricky. In the real world, the creator and data input folks will have a lot of knowledge about their information. Data will probably be entered from spreadsheets and reports. In this example I have shown one of the ways to use a cheat sheet (dropdown) on the Junction Table. To add a dropdown of the classes and Instructors on the Instructor_Classes Junction Table follow these steps: 1) 2) 3) 4) 5) 6) 7) Create a form using the Instructor_Classes Table as the foundation Go to Design View Under the Design Tab add a Combo box Follow the prompt to use the values from the Instructor Table Create another Combo box using the values from the Class Table Now we have a dropdown to remind us what the ID numbers are associated with each item Otherwise, we could use a separate digital copy of the information and search for the appropriate ID Running a query from the Junction Table The number one reason for using a Database is to run reports and collect data. The steps for collecting data by query from the Instructor_Classes Junction table would be as follows: This is an example of a 1) 2) 3) 4) 5) 6) Create Simple Query Wizard Select Classes and pick by sending from left side to right side any information needed Select Instructor_Classes and send over everything Select Instructor and pick by sending from left side to right side any information needed Name the Query Now the IDs have names associated with them for the report. Always test a database with real information before making it the One and Only collection of data. No matter how many times it is tested with fake information, it is very hard to catch errors. When the user sees that data does not correctly retrieve in a query that is NOT the time to discover a mistake in the layout. 20 Inner and Outer Joins – Access Database Example called ‘studentlocation.accdb’ An Access Database is a group of tables that have relationships to each other. For example, one table may have the list of students attending a university in the fall. The Student Table has all the personal information for just that student. Another table may have a list of all the High Schools along with their state location. When a report or inquiry needs to be run, the user wants to see understandable information, rather than ID numbers. An inner join will allow the creator to display names rather than code or ID numbers displayed in a temporary table for extraction or reporting. Types of Joins (Relationships) Inner Joins: Table 1 has records that correspond to Table 2 Rows. Only the Records that have common values in both tables will appear on the Report when a query is run. Most inner joins are automatically created when a relationship is created between two tables. Outer Joins: Table 1 has some records that correspond to Table 2 Rows. Alternatively, Table 2 has some records that correspond to Table 1 Rows. Always start with an Inner Join and then change it to an Outer Join if all the records need to be retrieved. In the Query Design view, double click the join and a Join Properties dialog box will appear. See the Join Properties that are listed. Pick the one that meets the needs of this report. If the report will show all rows that have corresponding data between two tables then use a full outer join, which requires an Union Query. Steps Create a query where the Table 1 (left outer join) has complete rows of information that should correspond to Table 2, which does not necessary have complete information Go to the Home Tab and select View and then SQL View Copy the SQL code by using CTRL+C Delete the semicolon at the end and press ENTER (return) Type in the word UNION and Enter Use the keystroke CTRL+V to paste the SQL code Next in the code you just pasted, change the words LEFT JOIN to RIGHT JOIN Delete the semicolon at the end of the FROM and press Enter Add WHERE Clause that says the value may be NULL Example below taken from http://office.microsoft.com/en-us/access-help/join-tables-and-queriesHA010096320.aspx Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) 21 For example, if the FROM clause is: In our example our clause will be: Select Student FROM Student LEFT OUTER JOIN hslocation ON student.stuID = hslocation.stuID UNION ALL SELECT FROM Student RIGHT OUTER JOIN hslocation ON student.stuID = hslocation.stuID You would add the following WHERE clause: WHERE Products.ID IS NULL Now type in a semicolon at the end of the WHERE clause Go back to the Design tab and in the Results grouping, click RUN Union all select Clause would look like this: SELECT Student.StuID, Student.StuName, HSLocation.StuHSLoc FROM Student LEFT JOIN HSLocation ON Student.StuID = HSLocation.StuID UNION SELECT Student.StuID, Student.StuName, HSLocation.StuHSLoc FROM Student RIGHT JOIN HSLocation ON Student.StuID = HSLocation.StuID WHERE NULL; More about Joins with example: Illustration for clarification with two tables. The table on the left is called Student; the table on the right is a list of High Schools state locations. StuID 14 19 6 20 31 Student StuName Susan Jim George Sam Helen StuID 14 19 6 20 39 HSLocation StuHSLoc Tennessee Florida North Carolina Texas Virginia The last row in the Student table does not appear in the High School Location Table. Outer Joins We have left outer joins, right outer joins and full outer joins. 22 SQL for a left outer join SELECT Student.StuID, Student.StuName, HSLocation.StuHSLoc FROM Student LEFT JOIN HSLocation ON Student.StuID = HSLocation.StuID; This mean we are joining on condition that the student’s IDs match the rows in the tables so we are temporarily combining 2 tables into 1 based on that condition. A left outer join keeps all the rows of the left table, and it does not matter whether there is data that matches in the right table. Therefore a left outer join would look like this: StuID 14 19 6 20 31 Student StuName Susan Jim George Sam Helen StuID 14 19 6 20 Null HSLocation StuHSLoc Tennessee Florida North Carolina Texas Null A right outer Join would be switched as follows: SELECT Student.StuID, Student.StuName, HSLocation.StuHSLoc FROM Student RIGHT JOIN HSLocation ON Student.StuID = HSLocation.StuID; Therefore the following temporary table: StuID 14 19 6 20 Null Student StuName Susan Jim George Sam Null StuID 14 19 6 20 39 HSLocation StuHSLoc Tennessee Florida North Carolina Texas Virginia Inner Joins Inner Joins return ONLY row that match. The SQL code for an Inter Join here would look like: SELECT Student.StuID, Student.StuName, HSLocation.StuHSLoc FROM Student INNER JOIN HSLocation ON Student.StuID = HSLocation.StuID; Here is the result of the Inner Join StuID 14 19 Student StuName Susan Jim StuID 14 19 Support Contact: Barbara Chamberlain (knightb@etsu.edu; 439-8611) HSLocation StuHSLoc Tennessee Florida 23 6 20 George Sam 6 20 North Carolina Texas As you can see, now we retrieve only the rows that completely match. We have no orphan entries showing. Inner or Outer Joins? Use an inner join if you only want to see those entries where the information is complete. The Inner Join displays all data where the Student’s exists and his or her data has been completed or in this example, when his or her location information has been entered. If all the information should be retrieved, with no regard to whether the location information has been entered, then use a left, right, or full outer join. This concludes Part I, II, and III of Access. Access will never be completely understood or mastered by most folks. The more it is used, the more skills are built on past knowledge. The more known about Access, the more complicated it can become as we try to push limits. Therefore, do not be intimidated. Try it. Start simple and built from there. Once you accomplish a few Queries, create a Form or two, and see how easy it is to quickly pull Reports and information, you will love using Access as I do. As long as the basic tables are maintained, the rest can be modified and changed. Thanks for participating in our eLearning workshops, and sessions. 24