You are on page 1of 36

Access 2010 Handouts

These handouts are available in the Blackboard course as individual files, but are provided here in one group.
Creating a New Database in Microsoft Access 2010 ................................................................................ 3 Create a Blank Database ....................................................................................................................... 3 Opening a Shared Database from the a read-only drive (like the S: drive) .............................................. 3 Opening a Previously Saved Database from Your N: Drive or Flash Drive................................................ 4 The Security Warning Dialog ..................................................................................................................... 4 Backing Up Your Database ........................................................................................................................ 4 Microsoft Access 2010 Data Types ........................................................................................................... 5 Number Types in Access ........................................................................................................................... 5 Using the Query Design Tool in Access ......................................................................................................... 6 Running Your Query .................................................................................................................................. 8 Saving Your Query ..................................................................................................................................... 8 Relational Operators in Access 2010 ............................................................................................................ 9 And .............................................................................................................................................................. 10 Or ................................................................................................................................................................ 10 Calculated Fields ..................................................................................................................................... 11 Defining a Calculated Field...................................................................................................................... 11 Text Fields and Concatenation ............................................................................................................ 12 Formatting a Calculated Column ............................................................................................................ 12 Date Functions in Access......................................................................................................................... 14 Using Format() to display dates .............................................................................................................. 15 Like and Wildcards .................................................................................................................................. 16 Wildcards: ........................................................................................................................................... 16 Totals Queries ......................................................................................................................................... 18 Counting Records and Displaying Totals ............................................................................................. 18 To create a Totals Query: ........................................................................................................................ 20 Additional Calculations ....................................................................................................................... 20 Adding Additional Criteria to a Totals Query ...................................................................................... 21

Access 2010 Handouts

Page 1 of 36

Parameter Queries ...................................................................................................................................... 23 Creating a Parameter Query ................................................................................................................... 24 How do I know what to type in the square brackets? ............................................................................ 25 Update Queries ....................................................................................................................................... 26 Creating an Update Query .................................................................................................................. 26 Adding Criteria .................................................................................................................................... 26 Running an Update Query................................................................................................................... 27 My Update Query doesnt work! ........................................................................................................ 27 Creating a Report in Access ........................................................................................................................ 28 Creating the Report: ............................................................................................................................... 28 Grouping and Sorting: ............................................................................................................................. 30 Totals:...................................................................................................................................................... 30 Conditional Formatting: .......................................................................................................................... 30 Mail Merge .................................................................................................................................................. 31

Access 2010 Handouts

Page 2 of 36

Creating a New Database in Microsoft Access 2010


Access works with files differently than other Office programsin order to do anything in Access, you need to create a Database file on a hard drive, flash drive, or network share. Word, Excel and PowerPoint can all work from a computers memory, and using the Save function to save as a file can be done after information has been added if youve ever forgotten to save a file in Word and then accidentally closed it, you may have been bitten by this behavior, since that work wasnt saved anywhere permanently! Access, on the other hand, always works from a saved database file on disk it always saves changes to the database on disk. This is good behavior, because it means that youll rarely lose data because it wasnt savedbut it also means that you have be careful when modifying data, since the Undo function is very limited. Create a Blank Database When you create a blank database, the first thing you must determine is where the database file will be saved, and what is will be called. For this class, its recommended that you save databases you create to your N: drive. 1. Open Access 2010 from the start menu icon. 2. Access starts up on the Backstage view. Click on Blank Database (near the top left of the window). 3. On the right side of the screen, the Blank Database form will appear. This is where you choose a location and a filename for your database. (The file extension .accdb will be appended automatically.) a. First click on the folder icon to choose a location for your database (e.g. your N: drive) b. Then fill in the name of your database. c. Click Create to create the database. It will open automatically.

Opening a Shared Database from the a read-only drive (like the S: drive)
Since Access works with files differently than other Office applications, you cant just double-click on a database file on a read-only drive to open it. Copy the database file your desktop, flash drive, or N: drive first, and then double-click on it to open it. Since Access saves changes while you are working, the database you are using to practice must be writable by youyou arent allowed to save things to a readonly drive like the S: drive, so Access will complain is youre trying to work with a database there.

Access 2010 Handouts

Page 3 of 36

Opening a Previously Saved Database from Your N: Drive or Flash Drive


To open a previously saved database that youve created for your own work (thats on the N: drive, the desktop, or your own flash drive), you can just double-click on the file icon to open ityou dont need to copy it first.

The Security Warning Dialog


Every time you open a previously saved database, youll see this warning under the ribbon:

This warning is to help protect you from viruses and worms that can be transmitted via Access files. If you receive Access databases from sources you do not trust (like unsolicited emails!), be wary of them! However, for this class, you can be reasonably sure that the databases I share with you are virus-free. And you can also be sure that databases youve created are! Before you can work in Access, click the Enable Content button in the warning bar. You can also click on the File button, choose Info, and then choose Enable Content next to the security warning. The security warning will disappear, and youll be able to work in Access.

Backing Up Your Database


You can make a backup copy of a database via two methods: Before opening the database, make a copy of the file using the Windows built-in file management tools. While in Access, go to the File menu, and choose Save Database As. Youll be prompted to save a new copy of the database with a new name.

Backups are a great idea if youre going to be making a lot of changes to a database, especially as you learnits the only way to return to a previous version of your data, since all changes you make are saved automatically!

Access 2010 Handouts

Page 4 of 36

Microsoft Access 2010 Data Types


Data Type AutoNumber Text Description An AutoNumber field creates unique values automatically when Access creates a new record. The AutoNumber field is primarily used for Primary Keys in Access. A Text field can contain values that are text, numeric or a combination of both. A text field can contain a maximum length of 255 characters. This is useful for short text data, like names or titles. A much larger version of the text field, allowing storage of up to 2 GB of data. The Number field can store numeric valuesthe most common types of Number field are Long Integer which only stores integer values, and Double, which can store decimal values as well. The Date/Time field allows storage of date and time information. The Currency data type stores values in a monetary format. Boolean data storage of true/false | yes/no | on/off values. The OLE Object field stores images, documents, graphs etc. from Office and Windows based programs. The maximum data size is 2 GB, although this will slow down a database. The Hyperlink field type is used to store web addresses. This has a maximum size limit of 1 GB of data. The Attachment field type is used to store images, spreadsheet files, documents, charts and other types of supported files to the records in your database.

Memo Number

Date/Time Currency Yes/No OLE Object

Hyperlink Attachment

Number Types in Access


Byte For integers that range from 0 to 255. Storage requirement is a single byte. Integer For integers that range from -32,768 to +32,767. Storage requirement is two bytes. Long Integer For integers that range from -2,147,483,648 to +2,147,483,647. Storage requirement is four bytes. Single For numeric floating point values that range from -3.4 x 1038 to +3.4 x 1038 and up to seven significant digits. Storage requirement is four bytes. Double For numeric floating point values that range from -1.797 x 10308 to +1.797 x 10308 and up to 15 significant digits. Storage requirement is eight bytes. Replication ID For storing a globally unique identifier that is required for replication. Storage requirement is 16 bytes. Note that replication is not supported using the .accdb file format. Decimal For numeric values that range from -9.999... x 1027 to +9.999... x 1027. Storage requirement is 12 bytes.

Access 2010 Handouts

Page 5 of 36

Using the Query Design Tool in Access


The Query Design Tool is accessed from the Create ribbon in Access 2010.

Click on the Query Design button to begin creating a new query. NOTE: The Query Wizard tool can be helpful to start with, but you will need to enter Query Design mode to modify your queries even if you use this tool.

The first step when creating a query is to select one or more tables to use as the data source. Click on the name of the table to highlight it, then click Add to add that table to your query.

When finished adding tables, click Close.

[NOTE: You can return to this item by clicking on the Show Table button while editing your Query.]

Access 2010 Handouts

Page 6 of 36

Once youve chosen tables for your query, you can add fields to display by choosing them from the drop-down box near the bottom of the window. If you are using multiple tables, field names will be prefaced by the table name, followed by a period. For example, the Title field of the Movies table will be denoted by Movies.Title. The TableName.* item (for example, Movies.*), is a special item that represents all of the fields on that table. This is useful if you query should return all the available fields!

Each column in the design view represents a column that will be used when your query is run. If the Show checkbox is checked, that column will display in the final results. If the column is unchecked, it will not display in the query output.

In the Criteria area, enter any selection criteria that will limit the amount of data that is displayed. If no criteria are entered, all data from the table(s) will be displayed. The Criteria area requires the use of relational operators to properly define what youre looking for some operators are: = Equals > Greater Than < Less Than >= Greater Than or Equal To <= Less Than or Equal To <> Not Equal To

Access 2010 Handouts

Page 7 of 36

Besides using the symbols above, here are some general rules for the correct formatting of your Criteria statements: The relational operator symbols (like those above) go BEFORE your criterion. (example: >50 or =USA) Any text that youd like to match should go in double-quotes (example: USA, Robert Redford Numbers should NOT go inside quotes. Commas and currency markers such as the dollar sign ($) should NOT be used. (example: >50000 NOT >$50,000 ) Dates should be formatted like this: #mm/dd/yyyy# (example: # 10/31/2011#)

Also, dont forget: Adding additional items to the Criteria row will make your query more specificthat is, it will narrow your results. (This is also called the And row.) Adding items to the or: row or below will make your query more generalthat is, it will tend to find more matches, increasing your results.

Running Your Query


Once youve set up a query, youll need to run it in order to see the results. Click on the Run button (a large, red exclamation point!) to view your query results.

When in query view mode, you may return to the query design mode by clicking on the View button near the upper left corner of the window.

Saving Your Query


Queries are a powerful database tool because they can be saved and stored in your database, and can be re-run at any time. When queries are run, they always contain the most current data available. Save a query by clicking on the save icon next to the office button in the top left corner of the window. Choose a name and click OK to save it.

Access 2010 Handouts

Page 8 of 36

Relational Operators in Access 2010


Operator >10 <10 >=10 <=10 =10 !=10 <> 10 =#3/29/2011# Between 3/1/2011 and 3/29/2011 =Text <>Text Is Null Is Not Null Description Greater than ten Less than ten Greater than or equal to ten Less than or equal to ten Equals ten Does not equal ten Does not equal ten Date is 3/29/2011 Date is between 3/1/2011 and 3/29/2011 Text field is Text Text field is not Text Field is empty Field is not empty Example Matches 11, 10.001 9.99, 8 11, 10.001, 10 10, 9.99, 4.56 10 9.99, 14.5, 10.01, 8 9.99, 14.5, 10.01, 8 3/29/11 3/1/2011, 3/5/2011, 3/14/2011, 31/9/2011 Text, text, TEXT Bob, R2D2, Tex Empty Fields Fields with any data Does NOT Match 9.56, 10 10, 13.45 9.99, 4.56 10.01, 11 9.99, 11, 10.001, 9 10 10 3/29/2010, 3/30/2011 2/28/2011, 3/30/2011 Tex, xt, Bob Text, text, TEXT Fields with any data Empty fields

Access 2010 Handouts

Page 9 of 36

And
Logical And decreases the amount of results by limiting the criteria. For example a query to return Computer Science Majors And English Majors from a student database returns only double majors in Computer Science and English, that is, only records that match both criteria. The matching area below is shown in darker blue. In Access, the And keyword can be used, or criteria can be added across columns in the Query Design View.

Match

Computer Science Majors

English Majors

Or
Logical Or increases the amount of results by expanding the criteria. For example a query to return Computer Science Majors Or English Majors from a student database returns all Computer Science majors, all English Majors, and all double majors in Computer Science and English. The matching area below is shown in dark blue, and includes all parts of both circles. In Access, the Or keyword can be used, or criteria can be added to the or: rows.

Computer Science Majors

English Majors

Access 2010 Handouts

Page 10 of 36

Calculated Fields
A database often contains information that can be calculated from one or more existing fields. For example, if a database for customer orders includes a PricePerUnit field, and an UnitsPurchased field, its easy to calculate total pricejust multiply PricePerUnit by UnitsPurchased. Since the data stored in the database allows us to easily calculate the total price, it would be redundant (and a potential source of errors) to have another field just to hold the total price.

But since the TotalPrice is a very useful bit of information, Access allows us to create a Calculated Field in a query. A calculated field does calculations on existing fields, and shows up as a column in a query just like a regular data field. The only difference is that the value in the calculated field is not stored in the database, it is calculated every time the query is run. This is nice behavior because if ever any of the values in a field change (for example, the PricePerUnit goes up), the calculated field will automatically update as well.

Defining a Calculated Field


To define a calculated field, in the Field row of a column in Query Design mode, you enter the following information:

Name of the Field

[FieldName1] (in square brackets)

Arithmetic Operator (like +, -, *, / ) or Concatenation operator (&) for merging text

[FieldName2] (in square brackets)

For example, to make the TotalSales field, we would enter:

TotalSales: [PricePerUnit] * [UnitsPurchased]

This is telling Access to make a column in our query called TotalSales that will be equal to PricePerUnit times UnitsPurchased. Access will automatically calculate this value for every row in our query.

Access 2010 Handouts

Page 11 of 36

Make sure each field name is surrounded by square brackets, and also pay attention to spellingthe field names must match exactly. If you get errors or a pop-up window asking for a Parameter, you have most likely spelled a field name incorrectly, or forgotten the square brackets.

Text Fields and Concatenation Besides being able to use arithmetic operators on numeric data types, you can use the ampersand character (&) to concatenate text data types together. Concatenation means merging text together, end to end. For example, in a record with a FirstName value of Homer, and a LastName value of Simpson the following:

Fullname: [FirstName] & " " & [LastName]

Will output: Homer Simpson the & operator takes all of the text and concatenates it together.

This operator is useful to format columns to display text fields in a certain wayfor example, in address fields or name fields.

Formatting a Calculated Column


Access is generally pretty good as guessing the correct format for a calculated column based on the data types of the fields used in the calculation. Sometimes you do want to change how a column is formatted thoughto force it to appear as currency, or with a certain number of decimal places.

In Query Design view, right-click on any column and choose Properties to display the Property Sheet for that columnit will appear as a pane on the right side of the Query

Access 2010 Handouts

Page 12 of 36

Design window. Alternately, you can click once a column to select it, and then click on Property Sheet in the Query Design ribbon to display the Property Sheet.

In the Property Sheet, choose the Format you would like for the column. Some options are:

Currency (like $42.57) Fixed (a fixed number of decimal places, like 42.57) Percent (like 42.57%) Short Date (like 10/31/2011) Long Date (like Monday, October 31, 2011

Choosing an option in the Format row will force that column to appear in that format. This technique can be used for all columns in your query.

Access 2010 Handouts

Page 13 of 36

Date Functions in Access


Since many databases include date or time fields, Access provides a lot of ways to work with date/time values. Just like in Excel, you can add or subtract date values in order to find a difference in days, for example, [ResignationDate] - [HireDate] Will give you the difference between the two dates in days. There is also an Access function that give you todays datethe Date() function. So the following: Date() - [HireDate]

Will give you the number of days that have passed since the HireDate. Below is a list of useful date functions:
Function Date() Now() Time() Day([datefield]) Format([datefield], <format>) Hour([timefield]) Description Gives today's date. Returns the current date and time. Returns the current time. Returns the day of the month (1 .. 31) of [datefield]. Returns [datefield] as a string of text in the format specified. (See below for examples.) Returns the hour of [timefield] as a number from 0 to 23. Note that midnight is 00:00 and that means that midnight "tonight" is actually tomorrow. Returns the minute of [timefield] as a number from 0 to 59. Returns the month number of [datefield]. Returns the seconds component of [timefield] as a number from 0 to 59. Returns the year number of [datefield]. Gives the day of the week as a number from 1 to 7.

Minute([timefield]) Month([datefield]) Second([timefield]) Year([datefield]) WeekDay([datefield])

Access 2010 Handouts

Page 14 of 36

Using Format() to display dates


Most of the time, you'll want to display dates in a specific format without storing that format as part of the date. The Format() function allows you to display any individual date component without affecting the stored date value. To display a single component, use the appropriate format code. For instance, the following expression would return only the day of the month as a number (1 through 31): Format([datefield], "d") If you want a leading zero, use dd instead of d. The table below contains more individual component formats. d dd ddd dddd m mmm mmmm yy yyyy Returns the day of the month as a number, with no leading zero: 1, 2, 3, and so on. Returns the day of the month as a number, with a leading zero: 01, 02, 03 and so on. Returns the day of the week as a three-letter abbreviation: Mon, Tues, Wed, and so on. Returns the full name of the day of the week: Monday, Tuesday, Wednesday, and so on. Returns the month as a number, 1 through 12. Returns the month as a three-letter abbreviation: Jan, Feb, and so on. Returns the full month name: January, February, and so on. Returns the last two digits of the year: 06, 07, and so on. Returns a four-digit year: 2006, 2007, and so on.

When using Format(), remember that the resulting value is a stringa data type for text. You'll use Format() to display dates, but don't use it when you must use the results in mathematical equations, for example, when comparing datesif you want to compare dates, use Year(), Month() or Day() instead!

Access 2010 Handouts

Page 15 of 36

Like and Wildcards


A wildcard is a special symbol that takes the place of a unknown character or set of charactersit is used in criteria in order to match several items. In Access queries, wildcards are used with the special operator Like, which indicates that instead of an exact match, youre looking to match items that fit a certain pattern. The pattern is stated by using wildcards. Like statements always take the form:

Like <<criteria with wildcards>>


Where the criteria with wildcards are enclosed in double-quotes. Wildcards: Wildcards used in Access include: * (the asterisk): matches any number of characters (including zero characters!) ? (the question mark): matches exactly one character [a-l] : matches any letter from a to l. (In Access, this is NOT case-sensitive.) [a,d,l] : matches the letter a, the letter d, or the letter l. (In Access, this is NOT case-sensitive) Examples:

Criteria Statement Like * Like B* Like *red Like 1/1/* (for a date field) Like C??

Like *a-c+* Like *d,l+*

Matches Anything Anything that begins with B, e.g. Bob, Bill, B, Breakfast Anything that ends with red, e.g. tired, Fred, red, Winnifred Dates on January 1st of any year Any three letter word starting with c, e.g. cat, car, cot. Each match MUST have three letters. Anything that begins with A, B, or C, e.g. Acrobat, Bottle, Chant Anything that begins with D or L, e.g. Donut, Lake, Discount

Access 2010 Handouts

Page 16 of 36

Access 2010 Handouts

Page 17 of 36

Totals Queries
In a regular query on an employee info database, we can return a list of everyone who lives in River Forest, IL by creating a query like this:

Our criteria for City and State are set, such that well return a list of employees whose City matches River Forest, and whose state matches IL. In a query like this, each matching record will be shown on one row of your query results. Counting Records and Displaying Totals As you recall, a query asks a question of our data. Sometimes, when creating queries, we dont want to see every matching record, but we want to see some summary of the data in the matching records. For example, what if we just want to know how many employees live in each city in our database, but we dont care about the individual matches? In a case like that, we create a totals query to group matches together in our results.

In the image above, on the left you see a query showing a different row for each matchone row for each record. This

On the right, you see a totals query that is summarizing the matches by counting how many times each city and state combination shows up on the list.

Access 2010 Handouts

Page 18 of 36

means that same city and state combination appears many times.

Access 2010 Handouts

Page 19 of 36

To create a Totals Query: 1. First, create a query containing your desired fields as you normally would. 2. Next, on the Query Design Ribbon, in the Show/Hide group, click Totals. This is a toggle on or off.

A new Total row appears below the Table row in your datasheet. Youll see that the default setting for each field in the query in the totals row is Group By 3. In the Total row, click the field that you want to count up, and then select Count from the list.

What this query design means is that for every combination of unique values in the City and State field, the number of matching records will be counted up and displayed. 4. Click the Run icon to see the results of the query:

As you see, each City/State combination appears on one line of the results, and the third column displays the number of records that have that combination in the City and State fields. From these results, we can see that 21 records match River Forest, IL. Additional Calculations In addition to counting a number of records, other options in totals queries can be selected: Count, for counting the number of records in a category Sum, for summing a column of numbers.

Access 2010 Handouts

Page 20 of 36

Average, for averaging a column of numbers. Maximum, for finding the highest value in a field. Minimum, for finding the lowest value in a field. Standard Deviation , for measuring how widely values are dispersed from an average value (a mean). Variance, for measuring the statistical variance of all values in the column.

For example, in this query, we are grouping by the City/State again, but have selected the HourlyWage in the third column, and have chosen Avg.

This query will show the Average HourlyWage for each City/State pair.

Adding Additional Criteria to a Totals Query In order to add criteria to a totals query, for example, to limit our results to just employees in Michigan, we add a column containing the field(s) wed like to apply our criteria to, and choose Where in the Totals row. In the example below, there is a fourth column, the State field, and Where has been chosen in the Total row. The criterion MI has been entered in the Criteria row, and the Show box in UNCHECKED. In fact, if you select Where in the Total row, the show box must be unchecked or youll get an error message when trying to run the query.

Access 2010 Handouts

Page 21 of 36

The results of our new query show the Average of the HourlyWage fields for each City/State pair, but only for those records where the State field matches MI.

Access 2010 Handouts

Page 22 of 36

Parameter Queries
A parameter in Access is a value (e.g. a number, a date, or a text string) that is provided by the user, and which can then be used in the criteria area of a query.

When you run a query containing parameters, you will see a box labeled Enter Parameter Value pop up. In this box, you can type a number, date, or text string, and then click OK in order to run a query based on the values you provide.

In the example picture to the right, the query is asking for a year. If you enter 2011, the query will then run, using 2011 as the value for the year. EACH TIME a parameter query is run, it will prompt for information, meaning that the results of a parameter query will depend on what is entered in the box.

This behavior is very useful for creating general use queries that are very flexibleinstead of writing 50 separate queries to list people by state, you can write one parameter query to ask for a state to look for, saving yourself a lot of work!

Access 2010 Handouts

Page 23 of 36

Creating a Parameter Query


Parameter queries are created just like regular queries via the Query Design tool. You add your columns as usual. In the sample below, 4 columns have been added to a query.

In the Criteria row, you see the text:

>[Enter Number of Hours]

By putting [Enter Number of Hours] in square brackets, we are letting Access know to prompt the user for the information that will go in that space. The greater than symbol before the first square bracket indicates that, for whatever value I type in the prompt, I want the WeeklyHours field to show me all values that are greater than that value. If I type 30, my query will match all records where the WeeklyHours field is greater than 30.

Access 2010 Handouts

Page 24 of 36

How do I know what to type in the square brackets?


There is only one rule to what you should enter between square bracketsyou MAY NOT use an existing field name. This is because Access uses square brackets to denote field names as well as parameters. If you use an existing field name, Access will assume that you mean the field and will not prompt you for the parameter.

Besides not using an existing field name, you can use whatever youd likea good choice is always something phrased as a question, since Access will display that in the dialog box when asking for a response.

[Which Year?] [What is the maximum cost?] [What is the Start Date?]

Remember how Access prompts you to enter information if you misspell a field name in square brackets? Now you know why it does thatif its in square brackets, and it isnt a field name, its a parameter, and Access will ask you for a value!

Access 2010 Handouts

Page 25 of 36

Update Queries
Queries that allow us to display information are called Select queriesbecause they allow us to select which records to display. Select queries do not modify the underlying data at all. There are other types of queries, however, that can be used to change data in various waysthese are, as a group, called Action Queries. One type of action query is an Update queryan update query updates data in one or more fields by using a formula. Just like select queries, update queries can include criteria that limit matching records. Creating an Update Query Create a new query and select the table(s) that your query should use as a data source in the same way you create a select query. In the Query Type group on the Query Design tab, click on the Update button to indicate that this query should be an Update query. When you select Update, a new row called Update to: will appear in the query designer. Use this row to indicate how a given field will change when the query is run. In the example to the left, the HourlyWage field has been selected. In the update to: row, enter a formula to calculate the new value. Use [square brackets] to surround field names, just like youd use in calculated columns, e.g. [HourlyWage] * 1.05. This formula indicates that for each matching record, the HourlyWage field should be multiplied by 1.05 (a 5% increase). NOTE: The formula in the update to: row will almost always include a reference to one or more fields! And, usually, it will contain a reference the field name for that column. Notice in the example above that the Update to: row in the HourlyWage column contains [HourlyWage] * 1.05. This is, essentially, saying: Update the current HourlyWage field, and make it equal to the current HourlyWage * 1.05. If your update formula has only numbers and no fields, then you will likely be resetting EVERY value in your database to the same thing! Adding Criteria You can add additional columns in an update query for criteriaas long as the Update To: row is blank, that field will not be changed. In the example to the right, our update query will only change records where State is IL.

Access 2010 Handouts

Page 26 of 36

Running an Update Query You can run an update query by using the run button, just like a select query. However, since an update query changes data, there are some safeguards in place. When you run an update query, you will see a confirmation dialog:

Clicking Yes will update your database permanently, with no chance to undo the changes. Clicking No will do nothing. Notice that you are told how many matching records will be changedpay attention to this numberif it seems too high or too low, click no and recheck your query and criteria. After you click yes on this dialog, an update query runs, and you will not see any further confirmation the data in the database will have changed, however. One way to check if your update query has worked is to look at the database before and after to make sure. My Update Query doesnt work! Since an update query changes your data irreversibly, Access tries to prevent you from accidentally running them. The first defense against accidentally updating your data when you dont want to is the the confirmation dialog. The Security Warning when you first open a database also prevents you from running update queries. If your update query doesnt seem to do anything, look in the lower-left corner of the Access window for a message that says The action or event has been blocked by Disabled Mode. This means that you havent enabled dangerous content. When you first open a database, you see a Security Warning

Click on Enable Content in order to allow your Update query to work. If your update query isnt running and you dont see the Security Warning bar, save your work, then close and reopen the database, this time making sure to click Enable Content from the warning bar.

Access 2010 Handouts

Page 27 of 36

Creating a Report in Access


For this exercise, youll create a report that looks like the example shown to you. Grouping: The records shown in the report should be ordered and grouped according to the State and then the City fields. In addition to City and State , the columns must be in the following order: LastName (label this Last Name including the space) FirstName (First Name) HourlyWage (Wage Per Hour) Age When Hired (in years-- this is calculated based on the Birthday field and the HireDate field)

Other Report features: Sorting: In each City group, employees should be sorted from oldest when hired to youngest when hired. Formatting: HourlyWages between $10 and $15 should be displayed with a red font, underlined. Totals: HourlyWages should be totaled by city, and also show a grand total. The average age of all employees should be displayed at the bottom of the report. The city wage totals should be labeled Total Wages City Name for each city. The report should have a page number in the form Page x of y at the top right of each page, and show your name and the report title in the top left of each page. The report should show the date at the top right of the report.

Creating the Report:


1. Whenever you want to create a report, the first step is to create a query that displays the data youd like to include in your report. Create a query that includes all of the columns from the Employees table mentioned above. HINT: You will have to create a calculated column to display the Age when hired! Save your query and call it QueryForTheReport. 2. Now, run the Query that you have just created, and, while you are viewing the results, click on the Create tab, and click on the Report button. 3. This brings up the Layout View of the report creation tools. As youll see, your initial report will include the name of your query as a title, and will show all of the columns from your query.

Access 2010 Handouts

Page 28 of 36

4. The dotted lines in Layout View represent the page marginsyou can see that some of the columns are spilling over the right margin of the page. Resize the City, LastName, and FirstName columns by clicking on the column heading, then clicking and dragging right-edge of the column to make it skinnier. Do this until all of your columns fit on one page. 5. Double-click on the report title to edit itchange it to Your Name First Report. Use the Font tools on the Format tab to boldface the title, and increase the font size to 24pt. 6. Edit the column heading titles by double-clicking on them to match the titles given in the instructions above. 7. Now is a good time to save your reportuse Ctrl-S, or click on the Save button to save your report. Call it YourName-FirstReport. 8. You might see that the Age When Hired column consists of #s. Just like in Excel, a row of #s indicates that there are too many digits to display in the space given. If the Age column has digits in it, youll see that it lists the age down to 12 decimal place accuracy. Since you dont want to show the age with so many decimal places, adjust to formatting of this column by clicking in the Age column to select it, and choosing Fixed from the Formatting area. Use the decimal point buttons to set the age to display only 1 decimal place. 9. Access has provided a default image in the top left corner of the reportchange this image by clicking on the Logo button in the Design Ribbon, and choosing any digital image to replace it. (You can use the image attached in Blackboard called dominicanlogo.jpg.) 10. Access has also automatically included the date and time in the top-right corner of the report. Remove these boxes by clicking on each to select it, then clicking the Delete/Backspace key, or right-clicking and choosing Delete. Click on the Date and Time button in the Header/Footer group of the Design ribbon and add a box that displays the date in the format 6/13/2012 and does not display the time. Set the background of the date box to red and the font to white. 11. If your title box needs to be resized to show up on one line, do that now by selecting the box and dragging the edges. Almost every item in Layout View can be resized and moved in this way! 12. Add page numbers in the form Page x of y to the top of your report by clicking on the Page Numbers button. Right-align the page numbers. Youll see that the page numbers may appear on top of the column headersmake more space by clicking on any column header and dragging it downward. 13. Scroll all the way down the pageyoull see that Access has automatically added page numbers at the bottom of the report for you. (Notice how it says Page 1 of 1 as if this entire report would fit on one page? In Layout View, there are no page breaks, so you cant tell how many

Access 2010 Handouts

Page 29 of 36

pages a report will be. To do that, use Print Preview.) Since you just added page numbers at the top of the page, remove the page numbers from the bottom of the page.

Grouping and Sorting:


14. One of the requirements of this report is to group results by State and then Cityfor reports, grouping means to gather records that share a certain field value together into the same part of the report, and to emphasize this grouping by indentation. To group results together, make sure you can see the Group, Sort and Totals area at the bottom of the Report window. (If you dont see it, click on the Group & Sort button to turn enable this window. Click on the Add a Group button, and then choose which field to group onfor this first example, choose State. Notice how the report now groups all records by state. Click on Add a group again and choose City to group on city, too. Boldface the state and city labels to make them stand out more on the report. 15. Use the Add a sort button to sort the records in each group by age, from oldest to youngest.

Totals:
16. Youll see that Access has automatically added a grand total for the HourlyWage column, but it doesnt show up as currency. Use the Formatting area to display this total as currency. Right-click on the grand total box and choose Set Caption to label the grand total as Hourly Wage Grand Total. 17. Besides Grand Totals, Access can display totals by groupsyou can set these options by right clicking on the HourlyWage column, and choosing an option from the Total menu. Set up your report to show a group sum and grand total for the Hourly Wage, and a grand total showing the average age of all employees when hired. Label the average age using a caption.

Conditional Formatting:
18. You can change the appearance of any single item in a record based on criteria by using the Conditional Formatting button on the Format ribbon. Click on the HourlyWage column to select it, then click the Conditional Formatting button to set conditional formatting criteria. Set HourlyWages between $10 and $15 to display in red with underline.

Thats allyouve now created a complex, well formatted report based on a query!

Access 2010 Handouts

Page 30 of 36

Mail Merge
One very common use for data, especially contact data, is to use it to send them e-mails or letters. I'm sure you've received form letters or emails that have your name and even some other information about you inside of it--- a person isn't sitting down and typing each one of those letter individually, though. By using a tool called Mail Merge you can take data stored in a database and merge it into a word document multiple times-- for example, to generate a personalized letter to lots of people!

Performing a mail merge operation in Microsoft Word 2010 can be summarized in the following steps: 1. Create the main document The basic document for a mail merge the form letter contains the static text. 2. Connect the document to a data source The data source, a file that contains the information to be merge, can exist in a wide variety of data formatsmost often Access or Excel. 3. Add placeholders (i.e., mail merge fields) to the document Place mail merge fields, such as address blocks or greeting lines, in your main document. These fields are filled with information from your data file. 4. Preview and complete the merge operation As you merge your data into the main document, you can page through the output to verify that the operation worked as you intended. You can then either print out, email, or save copies of the merged document youve created. (steps borrowed from http://oit.wvu.edu/training/files/word2010_mailmerge.pdf )

Create the Main Document


A Mail Merge consists of two parts, a data source (for example, a list of names and addresses) and a word document (for example, a form letter) that has the text and layout options that are the same for everyone. To do a mail merge, first create a word document that has any static text, images, or layout (like page margins) that youd like each letter to have. Any document can work for this purposeyou can even start with an existing word document and modify it for use as a Mail Merge document.

Access 2010 Handouts

Page 31 of 36

Connect the Document to a Data Source


Now that you have a document, choose the source of your data. In this example, well use a student information database with names and addresses that is stored in an Access table. To connect the two: 1. In Word, go to the Mailings ribbon, and choose Start Mail Merge Step by Step Mail Merge Wizard. 2. This brings up a pane on the right side of the screen taking you through the steps to create a merge. For Step 1, select the type of document you are creating. In this example, were creating a form letter, so choose Letters, and then click Next. 3. On the next step, choose Use Current Document to use the word document youre currently editing as the basis for your merge. Click on Next Select Recipients 4. At this step were choosing our data source. Select Use Existing List, then click on the Browse button to find your data sourceeither an Access database or an Excel spreadsheet. For this example, were choosing an Access database called StudentContactList. Click Open to select the source.

5. After selecting a data source, if there is more than one table or query in an Access database (or more than one sheet in an Excel database), youll be presented with a window asking you to choose which table/query or sheet to use as the source. Choose the item that has all of the information you need to include in your letter. In this example, well choose the StudentContactList table. 6. When done, click Next- Write Your Letter in the Mail Merge pane.

Access 2010 Handouts

Page 32 of 36

Add Merge Fields to the Document


Once youve added a data source, you can now tell Word where to place the information from that source. To do this you add placeholders (called merge fields) to the document. A merge field shows where a piece of data from your data source will appear in the final document. 1. Find the place where you would like a piece of information from your source should appear. Common items such as the Address Block (mailing address information), and the Greeting Line (Dear Bob) are listed in the Mail Merge pane. Lets start by adding the address block. Position your cursor in the document where the address block should appear, then click on Address Block to add a placeholder. Youll see a dialog verifying what the block should look likewhen youve selected the options that you prefer, click OK to add the merge field.

In your document, youll see the merge field show up as <<AddressBlock>>. This will be replaced by individual addresses! 2. You can add any additional fields from your data source by clicking on More Items and choosing a field from the list. Each merge field will appear in your document with << and >> on either side of it. You can format merge fields (e.g. with font choices, boldface, etc.) just like regular text in Word. In the sample below, you can see weve added the AddressBlock, First_Name, Guidance_Counselor, and Previous_School merge fields into the document.

Access 2010 Handouts

Page 33 of 36

3. Once youre done adding merge fields, click Next Preview Your Letters to be able to see how the actual data will look inside of your document.

Preview and Complete the Merge


1. When you preview the merge, youll see the letter as it will appear when saveall of your merge fields will be replaced by data from individual records in your data source. Use the arrow buttons on the Mailings ribbon in the Preview Results group to see different records in the context of your letter. Click on the Preview Results toggle to switch between seeing the data and the merge field names. 2. If youd like to make changes to your letter, click on Previous in the Mail Merge pane. If youre satisfied with the results, click on Next: Complete the Merge.

Access 2010 Handouts

Page 34 of 36

3. If you are printing your letters, use the Print button to print them. If youd like to save your letters as a word document, click Edit Individual Letters. In either case, youll be prompted for which records youd like to mergeselecting All with create a letter for each record in your data source, current will only generate a letter for the current record you were previewing, and the from options allow you to specify a range of records to merge. Clicking OK will complete the process, either printing or creating a new document with all of the information! 4. If you choose Edit Individual Letters, a new word document will open containing the merge each letter will appear on a new page, separated by a Next Page Section Break. Saving this new document will allow you to open it later.

Access 2010 Handouts

Page 35 of 36

Final Notes
If you save your source document, that is, the document you added the merge fields to, whenever you open this document, Word will attempt to access your chosen data source. This means that, if youve chosen a database that is updated regularly, you can open up your document and immediately generate new letters, since the merge will already be set up! When opening a previously set up mail merge document, youll see a dialog box like this appear:

Clicking Yes will allow word to access your data source. In order to re-run the merge, go to the Mailings ribbon, and choose Finish and Merge, and then you can generate your new documents.

Access 2010 Handouts

Page 36 of 36

You might also like