access-2007
DESCRIPTION
http://class.no/wp-content/uploads/2011/02/Access-2007.pdfTRANSCRIPT
CONTENTS
What is a database made of? ................................................................................................................................. 3
Fields ................................................................................................................................................................... 3
Records ............................................................................................................................................................... 3
Files ..................................................................................................................................................................... 3
Key Fields ............................................................................................................................................................ 4
Data types ............................................................................................................................................................... 4
Logical/Boolean .................................................................................................................................................. 4
Alphanumeric/Text ............................................................................................................................................. 5
Numbers (Real and Integer) ............................................................................................................................... 5
Integers ........................................................................................................................................................... 5
Real ................................................................................................................................................................. 5
Date & Time ........................................................................................................................................................ 6
Selecting appropriate data types ........................................................................................................................ 6
Creating a report in Access ..................................................................................................................................... 8
Modifying reports, using layout view ................................................................................................................... 10
Opening layout view ......................................................................................................................................... 10
Understanding Layout view .............................................................................................................................. 10
Adjusting column width .................................................................................................................................... 10
Reorganising columns ....................................................................................................................................... 10
Deleting information ........................................................................................................................................ 10
Logos ................................................................................................................................................................. 10
Page Setup ........................................................................................................................................................ 10
Queries ................................................................................................................................................................. 11
Creating Queries ............................................................................................................................................... 11
Understanding Query Design view ................................................................................................................... 12
Query properties .............................................................................................................................................. 13
Criteria .............................................................................................................................................................. 14
<>, <, >, Between .. And .. ............................................................................................................................. 14
Nulls .............................................................................................................................................................. 14
OR and IN(.., .., ..) .......................................................................................................................................... 14
Importing csv files in Access ................................................................................................................................. 15
Wildcard Searches ............................................................................................................................................ 18
Summary in access ............................................................................................................................................... 19
Run time calculations in Access ............................................................................................................................ 21
WHAT IS A DATABASE MADE OF?
FIELDS
Each piece of information in a database is stored in a field; these individual data items have a data type and
can only hold information of that specific type.
EXAMPLE:
Name Harriet Johnson
RECORDS
Several fields grouped together are referred to as a record. Each record will hold several pieces of information
relating to one specific thing (i.e. a person)
EXAMPLE:
Name Harriet Johnson
Born 11. June 1974
Address 18 Elm Street
Phone 51554300
Married Yes
Education MBA
Occupation Accountant
FILES
A file is a collection of records; each record is structured in the same manner. This means that each record has
the same data fields, but stores information about different items (i.e. a person)
EXAMPLE:
Name Harriet Johnson Peter Parker Clark Kent
Born 11. June 1974 06. May 1978 01. February
Address 18 Elm Street 22 Elm Street 19 Smalville
Phone 51554300 51554301 51554302
Married Yes No Yes
Education MBA Photography Journalism
Occupation Accountant Photograph Journalist
KEY FIELDS
In order to separate the different records in a database we often use a key field. This field contains an ID or
something similar that is unique to that record.
EXAMPLE:
ID 11067565723 06067865542 01026556816
Name Harriet Johnson Peter Parker Clark Kent
Born 11. June 1974 06. May 1978 01. February 1965
Address 18 Elm Street 22 Elm Street 19 Smalville
Phone 51554300 51554301 51554302
Married Yes No Yes
Education MBA Photography Journalism
Occupation Accountant Photograph Journalist
DATA TYPES
All fields have a data type and can only hold information of that specific type.
We have four main data types: Logical/Boolean, Alphanumeric/Text, Numbers (Real and Integer) and Date
LOGICAL/BOOLEAN
Boolean, or logical data, can only hold either TRUE or FALSE. However this can also be expressed as yes, no, on,
off or with tick boxes
EXAMPLES
TRUE FALSE YES NO ON OFF
ALPHANUMERIC/TEXT
This data type can hold any character you can input, including symbols (¤, &, %, ”, @, etc.) spaces, normal text
and numbers
EXAMPLES
DOG “A little mouse” ABC123 [email protected]
NUMBERS (REAL AND INTEGER)
Numbers are, well, numbers. However we separate between two main types of numbers; Integer and Real
INTEGERS
An integer is a whole number, meaning that it cannot hold decimals. An integer can either be positive or
negative.
EXAMPLES
12 45 1274 1000000 -3 -5735
Real Numbers
REAL
A real number can hold both integers and numbers that have decimals. A real number can either be positive or
negative
EXAMPlES
1 1.4534 946.5 -0.0003
3.142
DATE & TIME
A Date & Time field can hold a specific date and/or time. It is usually preformatted so that all dates within the
database appear similar.
DATE EXAMPLES
25/10/2007 12 Mar 2008 10-06-08
TIME EXAMPLES
11am 15:00 3:00pm 17:05:45
SELECTING APPROPRIATE DATA TYPES
In a database all fields must have a data type and it is important that we select one that is appropriate for the
information we wish to store in that specific field.
Different data types have different properties, it is for instance not possible to use text for a mathematical
function.
EXAMPLE:
Numeric (Integer) > ID 11067565723
Text > Name Harriet Johnson
Date > Born 11. June 1974
Text > Address 18 Elm Street
Numeric (Integer) > Phone 51554300
Boolean > Married Yes
Text > Education MBA
Text > Occupation Accountant
THE ACCESS INTERFACE
The interface is divided into three main areas:
A - Ribbon
This is common for the Office 2007 interface and gives
you access to the different tools available.
B - Objects in the database
This lists all the different objects in the database,
objects may include:
- Tables
- Queries
- Forms
- Reports
C - Currently open object
In this area the current object will be opened
D - Field properties
When you’re working on a table in design view you can
access the different field properties here.
A - Ribbon
B - Objects in database
C - Currently
open object
D - Field properties
(only available in form design view)
REATING A REPORT IN ACCESS
1. Select the table you want to create a report from
2. Start the report wizard under the create ribbon
3. Select the fields you want to include in your report and add them by clicking the ‘ > ‘ button
You can add all fields by clicking the ‘ >> ‘ button
4. Click ‘Next’
5. If you want to group the information by a field select it and click the ‘ > ‘ button
6. Click ‘Next’
7. Select how you want to sort the data in your report
8. Click ‘Next’
9. Select the layout of your report
10. Select if the report should be printed in portrait or landscape
11. Click ‘Next’
12. Select a style for your report
13. Click ‘Next’
14. Name your report appropriately
15. Click ‘Finish’
MODIFYING REPORTS, USING LAYOUT VIEW
You can make some basic adjustments to your reports, after you have created them, using layout view.
OPENING LAYOUT VIEW
You can access layout view by clicking the view button in the home ribbon, provided that you’ve opened the
report object
If you cannot find the home ribbon you’re probably in print preview and need to close it by clicking the ‘Close
Print Preview’ button in the Print Preview ribbon
UNDERSTANDING LAYOUT VIEW
In layout view you can select and modify the different elements of a report by clicking on them. Elements are
things like text boxes and column headings.
The dotted lines shows the margins and where the page breaks are.
ADJUSTING COLUMN WIDTH
If the information in a column only shows up as ##### it is because that column is to narrow, you can adjust it
by selecting the column heading and dragging the dividers between each column
If you double click on the dividers between each column it will adjust the column with to the heading
automatically.
Sometimes it might be necessary to adjust the columns so that they all fit on one page
Always make sure that all the information is showing in all the fields
REORGANISING COLUMNS
If you want the columns in a different order you can select the column heading and drag it to where you want
it.
DELETING INFORMATION
You can delete elements in your report by selecting them and clicking the delete button. If you delete a
column heading you will also delete the entire column of information.
LOGOS
You can insert a picture as a logo in your report by clicking the logo button, under the format ribbon.
PAGE SETUP
You can modify the page setup for a report in layout view by selecting the Page Setup ribbon
Use this to change between portrait and landscape without having to recreate the report.
QUERIES
In access you can create queries to search and filter data for reports
CREATING QUERIES
1. Select the table you want to base you query on
2. Start the Query Wizard under the Create ribbon
3. Select the Simple Query Wizard and click ‘OK’
4. Add the fields you want to use in your query and click ‘Next’
5. You now get two options:
a. Detail (shows every field of every record
In most cases this is the option you need to use, we will modify the query to fit our needs
later.
b. Summary
This option will allow you to make summary queries, for instance calculate the average of a
number, grouped by department
Select the type of query you need and click ‘Next’
6. Name your query appropriately and click ‘Finish’
UNDERSTANDING QUERY DESIGN VIEW
You can adapt the basic query, created with the wizard, to your needs by opening it in Design view.
Query design view is divided into two parts, Tables and Properties.
Tables
Properties
Tables shows the different tables associated with this query
Properties lists the different fields in use and the properties/criteria set for each of them
You can add fields to your query by dragging them from the tables and dropping them in the properties area.
QUERY PROPERTIES
Under the properties tab each column contains one field and the different properties for it are listed in the
separate rows.
The different rows are:
- Field
The name of the field
- Table
Table the field is from
- Sort
Will the query sort records based on information in this field?
Information can be sorted both ascending and descending
- Show
If checked this field will show up in result table, if unchecked it will not.
- Criteria
Records are selected based on the criteria set in this field.
- or
Additional criteria’s
If a record meets the criteria in either the Criteria field or the or field it will be displayed, you can add
more criteria’s by using the unlabeled rows below or.
CRITERIA
There are several criteria’s that you can use to select records from a table
The simplest criteria is the exact match. Just enter the value desired in the field's criteria section. Remember
that by using the Show option to eliminate the field from the display, you can specify criteria in fields the user
never sees.
<>, <, >, BETWEEN .. AND ..
You can also retrieve records where a field does not have a particular value by using "< >" followed by the
value you don't want. You can also use Not to exclude specific data.
Similarly, you can use >, <, >=, or <= for ranges. To select records with values between two values, use the
BETWEEN .. AND .. syntax.
NULLS
To select records with Null values, enter Is Null. The opposite is Is Not Null. For text fields, remember that zero
length strings ("") are not nulls.
OR AND IN(.., .., .. )
To select records where a field can have one of several values, use the OR command. You can simply say: "MD"
or "DC" or "VA".
IMPORTING CSV FILES IN ACCESS
1. Open the database you want to import the data into, or create a new blank one
2. Select the ‘External Data’ ribbon
3. Click the Text ‘file’ button under the import group
4. Select the data source by clicking the ‘browse’ button
The data source is the .csv file
5. Choose where to import the data
Make sure you select the appropriate import option:
a. Import the source data into a new table in the current database
This will create a new table where the data is stored,
this is the option you will use the most
b. Append a copy of the records to the table:
This will add the data you’re importing to an existing table in the database
c. Link to the data source by creating a linked table
This will create a table that is just referencing the external data,
We will never use this feature in class, DO NOT SELECT IT
6. Click ‘ok’ to open the Import text wizard
7. Select Delimited in the first screen and click next
When importing a .csv file the data are separated (delimited) by character, usually commas
8. Select the delimiter
Usually this will be a comma.
The data should show up in separate columns.
9. If the first row contains the field name, check this box
At this point your wizard should look something like this:
10. Click next
11. Make sure to select the correct data type for each field
Do this by:
a. Selecting the field (each column represents a different field)
b. Checking the field options above the table
12. Check that access will handle the different data correctly
Do this by:
a. Clicking the ‘Advanced’ button
b. Select the correct date order (DMY = Date Month Year, MDY = Month Day Year)
c. Select the correct decimal symbol (usually period as comma is used to separate fields
d. Click ‘OK’
Select date order
Select decimal symbol
13. Choose whether you want to add a primary key or not and click ‘next’
You can let access add a new one, define a field as one or choose to create table without it.
14. Name your table and click ‘Finish’
If there are Boolean (Yes/No)fields
Once imported Access will display boolean field information as 0 and -1, to change this:
a. Open the table
b. Go to design view
c. Select the Boolean field
d. Under the field properties change the format to: Yes/No
WILDCARD SEARCHES
Sometimes, you need to search for a particular letter or digit. Combined with the Like command, wildcards let
you specify such criteria. These are the wildcard characters Microsoft Access uses:
? Single Character
* Any number of Characters
# Single Digit
[..] Character List
[!..] not in Character List
EXAMPLE
- If you are interested in a text field where the second letter is "a", the criteria would be:
Like "?a*".
- If you were seeking values where the second letter could be an "a" or "e", the criteria
would be: Like "?[ae]*".
- The opposite of this (all values that do not have "a" or "e" as the second letter) is
performed by adding an "!": Like "?[!ae]*".
- Finally, to select a range of letters (say "a" through "e"), add a dash between the
letters: Like "?[a-e]*".
- To search for a wildcard character, enclose the value in brackets. For instance, to find
values that end in a question mark, use this: Like "*[?]"
SUMMARY IN ACCESS
The summary function in access can be used to do simple calculations on numeric fields, grouped by another
field in the table.
To create summaries in access we use queries:
1. Create a query, containing only the field you want to group by and the one you want to make a
summary of
2. In the Query design click the Totals button under the design ribbon
3. This will make another row, called Total, between the Table and Sort rows visible
4. Under the field you want to do your calculation, select an appropriate option from the dropdown:
Sum – Calculates the total of the values in each group
Avg – Calculates the average of the values in each group
Min – Finds the lowest value in each group
Max – Finds the highest value in each group
Count – Shows how many records there are in each group
First – Shows the first record in each group
Last – Shoes the last record in each group
5. Make sure the field you want to group by says Group By in the totals row
6. Run the query
Example
Consider the following data table:
Name Department Sales
John Shoes 39 000 NOK
Bob Jackets 15 000 NOK
Spencer Jackets 16 000 NOK
Laura Shoes 21 000 NOK
Mary Shoes 24 000 NOK
Jane Jackets 45 000 NOK
We want to find out, what the average sale, per department is, a summary query can tell us this. By telling
access that you want the average sale, the program will group people by department, add together their total
sales and divide it by the number of people:
To do this we need the following query:
And it gives us the table:
Department Sales
Jackets 25 333,33 NOK
Shoes 28 000 NOK
RUN TIME CALCULATIONS IN ACCESS
When creating queries we can ask access to perform some calculations each time we run the query, and show
the results in a separate column.
1. Create a query with the fields that you want to include
2. In an empty column, enter the name of the new field, followed by the calculation
Name: Number / 3
Name of the new field
A field used in the calculation A number used in the calulation
Operator for the calculation (divide)
The colon ( : )
signifies the end of
the field name
3. Each time you run the query it will perform the calculation for each record and display the result
EXAMPLE
Consider the following data table:
Name Department Sales
John Shoes 39 000 NOK
Bob Jackets 15 000 NOK
Spencer Jackets 16 000 NOK
Laura Shoes 21 000 NOK
Mary Shoes 24 000 NOK
Jane Jackets 45 000 NOK
Each employee gets 1 bonus point for each 175 NOK they sell for and can use these to buy things in the store.
We want to create a query that calculates this and displays the results in a column called Bonus.
To do this we need to use the following formulae:
To do this we need the following query:
And it gives us the table:
Name Sales Bonus
John 39 000 NOK 222,85
Bob 15 000 NOK 85,71
Spencer 16 000 NOK 91,42
Laura 21 000 NOK 120
Mary 24 000 NOK 137,14
Jane 45 000 NOK 257,14