18
www.jwalkonline.org/main [email protected] @MichaelJWalk Microsoft Access 2010 Part 3 Michael J. Walk It's about control: use advanced features of Access to control data entry, automate processes, and make database navigation easy. Now that you can use your database to store, access, and manipulate your data, add advanced control features to ensure data integrity, protect your database, visualize your data in charts, and make it easy to navigate.

Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

Embed Size (px)

Citation preview

Page 1: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

www.jwalkonline.org/main

[email protected]

@MichaelJWalk

Microsoft

Access 2010 Part 3

Michael J. Walk

It's about control: use advanced features of Access to control data entry, automate

processes, and make database navigation easy.

Now that you can use your database to store, access, and manipulate your data, add advanced

control features to ensure data integrity, protect your database, visualize your data in charts,

and make it easy to navigate.

Page 2: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

1 How to Use This Handout

Table of Contents Access Database Object Review ................................................................................................................... 2

Importing Data .............................................................................................................................................. 3

Importing from Excel ................................................................................................................................ 3

Advanced Table Design ................................................................................................................................. 5

Validation Rules ........................................................................................................................................ 5

Field-level rule ....................................................................................................................................... 5

Record-Level Validation Rule ................................................................................................................ 8

Calculated Fields ....................................................................................................................................... 9

Required Values ...................................................................................................................................... 10

Data Visualization ....................................................................................................................................... 11

Pivot Charts ............................................................................................................................................. 11

Creating a Chart on a Report / Form....................................................................................................... 12

Using Forms to Improve the User Experience ............................................................................................ 14

Using Command Buttons to Open Objects and Run Tasks ..................................................................... 14

Using Form Controls as Query Criteria ................................................................................................... 15

Creating a Basic Macro ............................................................................................................................... 16

Basic Database Maintenance ...................................................................................................................... 17

Backing up your Database....................................................................................................................... 17

Creating a Password for your Database .................................................................................................. 17

Page 3: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

2 Microsoft Access 2010

How to Use This Handout This handout serves as a point of reference for your workshop. However, you may also use the handout

after the class is over to help you remember how to perform some of the tasks covered during the

workshop.

Click Paths Throughout this handout, you will be given directions to perform a series of mouse clicks—also called a

“click path.” For instance, to save a change to an Access object, you should click on the File tab in the

ribbon, then click on Save. In this handout, that click path is displayed using a bold font for the words to

click on connected by a single right-pointing arrow ():

File Save

In some cases, you must find the correct section of the ribbon before clicking on an icon or button. In

these cases, the ribbon section will be highlighted in gray, for example:

External Data Import & Link Excel

In this example, Import & Link is a ribbon section.

Keyboard Directions You also will be given directions to press certain keys on your keyboard. There are two kinds of key press

sequences: (1) simultaneous and (2) sequential.

1) Simultaneous key presses refers to keys you have to hold down together to perform a task.

Simultaneous key presses are displayed using the plus sign (+) between the keys to be pressed

typed in caps. For example, the find box is opened by pressing CTRL + F. CTRL stands for the

control key. ALT stands for the alternate key. WIN stands for the windows key (only applies to

PCs with windows keys).

2) Sequential key presses refers to keys you have to press in sequence (one after the other—it is

not necessary to hold them down). Sequential key presses are displayed using a pipe character

(|) between the keys to be pressed typed in caps. For example, one way to save your file under

a new file name is to type ALT, then F, then A. This would be displayed as: ALT | F | A.

If you like keyboard shortcuts, Microsoft Office has provided a very robust listing of them at:

http://office.microsoft.com/en-us/access-help/keyboard-shortcuts-for-access-HP010341802.aspx. I

provide a lot in this workshop, but their list exhaustive.

Page 4: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

3 Access Database Object Review

Access Database Object Review 1. Table: stores our data. Without a table, we have no information in our database.

2. Form: allows us to view and enter data. Also useful for “user control” (i.e., helping making

interaction with the database easier).

3. Query: retrieves, summarizes, and manipulates information in tables.

4. Report: creates a printer-friendly and aesthetically pleasing presentation / summary of data

from a table(s) or query.

5. Macro: allows us to run complex or multiple tasks in sequence.

Importing Data Using Access import tools, we can import from Excel, text files, XML files, SharePoint, other databases

(e.g., Oracle, SQL), etc.

There are three basic types of import actions:

1. Import: creates a carbon copy of the source file and places that data in the Access database as a

table. No connection remains between the Access database and the source file.

2. Link1: creates a live electronic link to the source file. If a record is added to the source file, a

record is added to the linked access table.

3. Append: adds a carbon copy of the source file to the bottom of a selected existing Access table.

Importing from Excel 1. Click on External Data Import & Link Excel.

2. Browse to the desired source file (which Excel file you’re trying to import).

3. Choose your desired import action (import, link, or append)

1 Links are great when your database files are very large. By storing the actual data in the source file, you decrease

the likelihood that you will exceed the 2GB limit of an Access database file.

Page 5: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

4 Microsoft Access 2010

4. Answer the following series of prompts (some slight variation is possible, depending on which

import action you chose2.

a. Does the first row contain column headings (or field names)?

b. Assign the appropriate data type to each field.

c. Decide whether to choose your own primary key or to let Access add one.

{ --------------------------------------------------------

We will import data for this class together. Some points during the import:

1) Ratings sheet of RYRData_for class.xlsx

a. Data Types

i. RatingID Double

ii. RiderID Text

iii. TimeSent Date/Time

iv. Rating Integer

v. BusRoute Integer

vi. Complete Yes/No

b. Primary Key RatingID

c. Change Complete Lookup display to check box

2) Riders sheet of RYRData_for class.xlsx

a. Data Types

i. RiderID Text

2 When appending, your source file MUST contain field names in the first row. The field names in your source file

must exactly match the field names of your destination table.

Page 6: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

5 Advanced Table Design

ii. DOB Date/Time

iii. Subscribed Yes/No

iv. FirstRating Date/Time

b. Primary Key RiderID

c. Change Subscribed Lookup display to check box

3) Bus Lines.xlsx

a. Data Types

i. Number Integer

b. Primary Key Number

---------------------------------------------------------------------------------------- }

Advanced Table Design A well-designed table with not only provide all the right fields to collect very specific pieces of

information it also provides mechanisms to help reduce the probability for data error. Here are two

major features of table design that can be used to increase data integrity.

Validation Rules A validation rule is a rule that tells the table what qualities a cell value must have for that value to be

valid. For example, many tables have date fields where we enter past events. It is usually a good idea to

ensure that a date does not get entered that is in the future. We can do this using a validation rule.

Field-level rule

A field-level rule applies to values in a single field and can be used to check the appropriateness of the

value in a single field for a single record upon data entry. For example, let’s say you are entering the

dates of birth for a group of new college students. The date you type should not be in the future.

Therefore, we can set a field-level rule on our date of birth field to check if the date entered is not in the

future.

Let’s provide a validation rule that makes sure the DOB is before today.

Adding a field-level rule in datasheet view

1. Click inside the field you wish to add the validation rule to (DOB).

2. On your ribbon, go to Table Tools Fields Field Validation Validation.

Page 7: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

6 Microsoft Access 2010

3. Click on Field Validation Rule. This will open the Builder dialog box where you can provide the

validation rule. There are an infinite number of rules that you could use, but in this example,

you’ll have to type:

Now() is a common Office function. It returns the current date and time from your computer’s clock.

4. Then click OK. Your rule is now applied to that field.

Page 8: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

7 Advanced Table Design

5. If you want special text to pop up when someone violates that validation rule, then you must set

the Validation Message. Validation Message is found under Table Tools Fields Field

Validation Validation Field Validation Message.

Adding a field-level rule in design view

1. While in design view, click on the field that needs a validation rule. In the properties window

below, you will find a property called Validation Rule.

2. You may either type the rule directly in the box or click on the builder box to open up the

Expression Builder.

Page 9: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

8 Microsoft Access 2010

Record-Level Validation Rule

If you want a validation rule to check the appropriateness of values in 2 or more fields in a given record,

you must apply a record-level validation rule.

Let’s create a rule to make sure that the FirstRating is after the DOB.

Adding a record-level validation rule in datasheet view

1. Go to Table Tools Fields Field Validation Record Validation

Page 10: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

9 Advanced Table Design

2. This will open the Expression Builder for you to type the validation rule.

[DOB] < [FirstRating]

3. After setting the rule, it is best to set the Record Validation Message.

To set a record-level Validation Rule in design view

1. In design view, in the ribbon, click on Table Tools Design Show/Hide Property Sheet

2. In the TABLE’s property sheet, you will find the validation rule cell. Type the rule in that cell and

provide the message below that cell.

Calculated Fields You can add fields to your tables that are calculated based on values in other fields in the same table.

For example, if you have a field containing minutes, you could add a calculated field that calculates the

age (in decimal years) when the person provided their first rating.

To add a calculated field in datasheet view

1. Using, the ribbon, go to Table Tools Fields Add & Delete More Fields Calculated

Field select your field type.

Page 11: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

10 Microsoft Access 2010

2. This will bring up the Expression Builder box. Type the calculation in the box and you are done.

([FirstRating] – [DOB]) / 365.253

3. Change the name of the field by double-clicking on the field heading and overwriting the current

name.

To create a calculated field in design view

1. Go to the next blank field. In the data type drop-down, find Calculated

2. This will bring up the Expression Builder box. Type the calculation in the box.

Required Values If you have a field in your table that CANNOT be left blank when a new record is inserted, change that

field’s Required property to TRUE.

In datasheet view:

1. Click in the field that you wish to make required.

2. In the ribbon under Table Tools Fields Field Validation Required.

3 362.25 is the average number of days in a year.

Page 12: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

11 Data Visualization

Data Visualization

Pivot Charts You can turn any query or table in a pivot chart / pivot table. (A pivot chart is a graphical representation

of a pivot table; I will use pivot chart throughout this section, but am referring equally to either one.)

1. Switch to pivot table view by using your ribbon: Home Views Pivot Chart

2. This will bring up the Pivot Chart view. Pivot charts contain 4 sections:

a. X-axis (categories)

b. Y-axis (data values)

Page 13: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

12 Microsoft Access 2010

c. Series (legend)

d. Filters

3. At the right of your screen, the Chart Field List should be displayed. Simply drag and drop the

fields needed to create the chart into their proper location.

Creating a Chart on a Report / Form You can also embed a chart (graph) into a report or form.

1. Create a new report in design view.

2. Use the Chart tool in the ribbon, and place the chart in the form’s design area.

Page 14: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

13 Data Visualization

3. Follow the prompts to add the graph.

4. To edit the appearance of the graph, double-click on it.

5. You can:

a. Change the chart type

b. Edit font sizes, font types, font colors

c. Add/remove data labels

d. And many more

Page 15: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

14 Microsoft Access 2010

Using Forms to Improve the User Experience

Using Command Buttons to Open Objects and Run Tasks It is very common to provide your database users with a form that will allow them to perform tasks (run

reports, run queries, import data) with just a click of a button.

General Procedure for Using Forms for User Control

1. Create all necessary objects to perform the task independent of a special button.

2. Create a blank form. Add a button to it that will perform the necessary task.

Example task: running a query by clicking a button

1. Create the query that you wish to run. Save the query under a unique name.

2. Create a blank form by going to Create Forms Blank Form

3. Add a title to the form (if needed; Form Layout Tools Design Header/Footer Title)

4. Add a button to the form by clicking on the button icon in the ribbon, and then clicking in the

blank space on the form.

5. This will open the Command Button Wizard.

6. Under the Category Miscellaneous, you will find the Action, Run Query. Select this. Then select

the query you wish to run.

7. Edit the text that will appear on the button.

8. You’re done.

Page 16: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

15 Using Forms to Improve the User Experience

Using Form Controls as Query Criteria Sometimes you not only want to run a query from a form, but you also want to allow the user to specific

criteria that the query should use. By creating a couple of text boxes on the same form that runs the

query, we can allow the user to specific a start date and end date for a particular query.

1. Add two text box controls to the form by clicking on the text box control icon in the ribbon and

then clicking on the blank form where you want to place the box.

2. Open the Property Sheet for the first text box. On the Property Sheet, click on the Other tab.

Change the Name property to StartDate.

3. Do the same for the second text box; however, name it EndDate.

4. Edit the query’s design so that, in the criteria for the TimeSent field, you have the following

syntax:

Replace Form1 with whatever the form’s saved name will be.

Replace StartDate and EndDate with the actual control name (if different).

5. Now, when the query runs, it will be looking for this form to be open and for these text boxes to

have dates typed into them so the query can use those dates as criteria for retrieving the

information from the table.

Page 17: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

16 Microsoft Access 2010

Creating a Basic Macro Basic Process

1. Click on Create Macros and Code Macro

2. Use the drop-down menu to select the desired action(s)

3. Complete all required properties for that action

4. Save

5. Click run

Example task: Create a macro to export query results

1. Click on Create Macros and Code Macro

2. Select ImportExportSpreadsheet in the dropdown box.4

3. As seen above, you will get a series of properties or settings to complete.

4. Transfer type: Export

5. Spreadsheet type: Excel Workbook

6. Table name: (name of table/query to export)

7. File name: (full path of desired destination file, including file extension)

8. Save the macro.

9. When you run the macro, it will first access the table/query, then prepare the results for export

to an Excel file that will be dumped in the location you specified in the File Name setting.

4 If this option is not available, be sure that Show All Actions is selected in the ribbon.

Page 18: Microsoft Access 2010 - Welcome to your first page!jwalkonline.org/main/wp-content/uploads/2013/09/Access...2 Microsoft Access 2010 How to Use This Handout This handout serves as a

©2013 JWalk Professional Services Part 3 v2.0 (rev 9/7/2013)

17 Basic Database Maintenance

Basic Database Maintenance

Backing up your Database It is important to create regular backups of your database. The more critical the information is, the more

important it is to create regular backups.

1. In the ribbon, click on File Save & Publish Back Up Database

2. Follow the prompts to create the backup.

3. I recommend keeping the database name the same and then appending the date/time of the

backup to the filename to easily tell which back up is the one you want.

Creating a Password for your Database Placing a password on your database keeps your database (tables, forms, etc.) secure from others. There

IS NO PASSWORD RETRIEVAL, so, don’t lose your password.

1. In the ribbon, click on File Info Encrypt with Password

2. Type your password twice when prompted

3. Don’t forget it