Ms-Access Notes
Ms-Access Notes
Ms-Access Notes
MICROSOFT ACCESS
Database Management
A database is a collection of any related information/data that is stored together under
one logical structure. It is a collection of information related to a particular subject or
purpose (people, items, places, events etc); such as tracking customer orders or
maintaining a music collection. Examples include - Telephone directory, Flight-
schedules, Employees records, Stock inventories, Customer details, Class register, a
price list, etc.
A database management system (DBMS) is a tool or a program that allows one to
create, maintain, update and store the data within a database. Examples of DBMS
programs include:-
i) Ms-Access
ii) FoxPro
iii) Dbase III Plus
iv) Dbase IV
v) Dbase V
vi) Oracle
vii) Lotus Approach
viii) Visual Basic
Microsoft Access can be installed as a stand-alone program but it is mainly found within
the Ms-Office suite. It is very useful for routine and simple database management tasks
but it has a limit to the maximum number of records it can comfortably deal with. For
performing intensive database management you need powerful and advanced software
such as: Oracle or SQL server (used by K.P.L.C.).
These powerful programs allow simultaneous database entry and can accept up to 2
million new records daily.
Dbase and FoxPro were the biggest competition for Access in 1980’s and 90’s. The
Microsoft Company owns FoxPro and this has pushed Access into the position of
DBMS.
Ms-Access is commonly used because of its multiple tables and database objects like
queries, forms, reports, macros, modules etc that can be created within a database file.
Advantages of DBMS
You can link many database tables and source data from these tables.
With modern equipment there is easy recording of data.
There is first retrieval of stored information.
It is easy to maintain the database.
It is easy to analyze stored information and to prepare summary reports and charts.
Types of Databases
1. Hierarchical: - Records are stored in multiple levels, units further down the system
are subordinate to the ones above (in a tree-like structure). In most cases
hierarchical database uses arrows to connect data at different levels.
2. Relational Database: - Data elements are stored in a tabular format, in rows and
columns. Each column represents a field and each row represents a record.
The records are grouped under fields. Each field/column must have a title/fieldname.
This type of database is flexible and easy to understand.
Definitions
Table:- It is a collection of related data organized in rows and columns.
Field:- Single unit of information within one column in a table.
Fieldname:- It is a column heading/title or a label for a field.
Records:- A set of all fields within one row in a table.
Database file:- A collection of all tables and objects (queries, forms, reports etc) used
to manage data.
Designing a database
Before you create a database file, you need to decide on certain factors:
Determine the purpose of the database file.
Determine the type of tables that you may need.
Determine the fields that you may want to use.
Determine the type of objects you need in the database.
automate common tasks. For example, you can run a macro that prints a report
when a user clicks a command button.
vi) Modules – A small part of a program
At this point you can then click on the tab that has the Object you want to create and
follow the instructions provided in the resultant dialog box.
DATA TYPES
The data type determines the kind of data that a user can put in a field. Each data item
that you put into your database must fall within one of the following categories:
Text:- (Default) Alphabetical characters, symbols or combinations of text and numbers,
as well as numbers that don't require calculations, such as phone numbers. It can take
up to a maximum of 255 characters or the length set by the Field Size property,
whichever is less.
Numbers:- This only includes numeric digits - 0-9
Date/Time:- Allows one to enter a date or time depending on the formats chosen.
YES/NO:- Allows one to choose a true or false state e.g. (Married? - (either Yes or No))
Memo:- The same as Text but allows one to enter large blocks of text up to a maximum
of 65,535 characters. Any data put in the memo field cannot be viewed directly from the
datasheet view.
Currency:- Allows one to enter number then it automatically displays the numbers with
the default currency symbol as a prefix or suffix.
Auto Number:- Automatically numbers the records in the table. It puts automatic
numbers at the beginning of each record as you enter them one by one.
Hyperlink:- This links the fields to another table within the same database or in a
different database.
OLE Object:- Allows one to bring data and files from another program into the current
field. (Object Linking and Embedding).
Renaming a column
From design view:
- Select the field you want to rename, delete its name and type a new one then save
the table.
From Datasheet View:
- Double click the fieldname and type a new one, or
- Select the field, choose Rename column from Format menu and type a new name.
- Right-click the field name, choose Rename column and type a new name.
Inserting Fields/Column
Column/fields can be inserted both from Design and from Datasheet view.
From Design view:
In this view you can insert the new field anywhere within the table, e.g. at the end or in
between the existing fields.
Position the cursor anywhere, choose Rows from Insert menu and type the name for the
new field, or put the cursor at the bottom of the last field and type the name for the new
filed.
From Datasheet View:
In this view you cannot insert a new column at the end of the table and there is no way
of choosing your own data type unless you go back to design view.
Put the cursor where you want the new column to appear, choose Column from Insert
menu then double-click the default fieldname to type the correct name
Hiding a Column:
This is the process of removing a column from view without deleting it. You may want to
hide a column for two reasons; Prevent anybody from accessing its information or to
reduce the size of a database table for viewing or printing specific columns only.
Select the column(s) you want to hide and choose Hide Column from Format menu, or
right-click the column and choose Hide Columns from the displayed list.
Unhiding a column
This is the process of bringing back/displaying a hidden column.
Choose Unhide Column from, click all the columns that are hidden one by one and click
Close.
Freezing Columns:
This is the process of locking or making a column stationary so that it doesn’t move
during scrolling. If there are too many columns in a datasheet table, you can freeze the
first column(s) so that they don’t move when scrolling through the screen. When a
column is freezed it stays at the left-most position while the rest of the columns continue
to move/scroll in and out of view.
- Select the column, move to Format menu and select Freeze Columns, or right-click
the column and choose Freeze columns from the displayed menu.
To Unfreeze the column, move to Format menu and select Unfreeze All Columns.
You can then drag the unfrozen column back to its previous location.
SORTING:
This is the process of arranging records in a logical order, either in ascending or
descending order; Alphabetically, Chronologically, or Numerically.
The field you sort your records on is given the first priority in the arrangement of the
records.
- Select or position the cursor in the field to be sorted on.
- Click the Sort Ascending or Sort Descending button on the Standard toolbar, or
go to Records menu, select Sort, then choose either Ascending or Descending.
SEARCHING A DATABASE:
Access allows one to search for a string of characters within an entire database. This is
not a field or a record sensitive search. You can also find and replace data within a
table.
Finding Data:
- Select Find from Edit menu or press Ctrl + F or click the Find button on the Standard
toolbar.
- In the next dialog box, type the text to look for, choose any desired option and then
click Find First. To continue finding other occurrences of the same text, click Find
Next.
Replacing Data:
- Select Replace from Edit menu or press Ctrl +H.
- In the next dialog box, type the text to look for, type the replacement, choose the
necessary options and click Find Next.
- Click Replace to change the occurrences one by one, or lick Replace All to change
all the occurrences at once.
FORMATTING A TABLE
You can apply formatting features to the whole table at once. These features include:
Font, Colour, Size, Bold, Italic, Underline, Cell Outline, Cell Colour, Cell effects, etc.
All these can be applied from the Formatting toolbar or from the Format menu.
NB:
Any formats applied to the table will affect the whole table the same way i.e. you cannot apply
different formats for different fields or records.
Spell-checking a table
- Select the Spelling command from the Tools menu or press F7 key.
- Use the options inside the resultant dialog box to correct spelling mistakes if any.
PRINTING
You need to preview you table before printing it to make sure that everything is well
displayed. Use the Print Preview command under File menu, or the Print preview
button on the Standard toolbar.
To print a table;
Select the Print command from File menu or press Ctrl + P.
The print dialogue box has the following options:
Printer:- Allows one to change the type/name of printer
Print Range:- Allows you to specify specific pages or parts of the table to be printed.
Copies:- Specifies the number of duplicates to be printed (produced.)
Collate – specifies the order of printing incase of you are printing multiple pages and
multiple number of copies.
Print to file:- Allows one to save the file such that it can be printed using Ms-Dos.
When the command is selected and you click Ok, Access will ask you to enter a
filename(i.e. it is not printed directly on the printer). The name is given an automatic
extension of PRN (printer file). The printer file can then be printed form any computer
having Ms-Dos by using the print command.
E.g. C:\>Copy A:Table.prn>PRN or A:\>Print Table.prn>PRN
PRIMARY KEY
This is a field that uniquely identifies each record in the database table, just like a
number-plate uniquely identifies each car on the road. Examples of Key fields include:-
Identification numbers, Registration numbers, User codes, Admission numbers etc.
When you are setting a field as a primary key, make sure it is a field where no two
records can share the same information.
All the records will be automatically sorted by the entries of the primary key fields in the
Ascending order.
The primary key field cannot be left empty whenever you are typing new records in the
table.
Make sure you set the primary key before typing any records in the table.
If you don’t set the primary key yourself, whenever you are saving a new table, Access
will ask you if you want a primary key. If you choose No, the table will be saved without
a primary key but if you choose Yes, Access will automatically insert a new field by the
name ID as the primary key and insert AutoNumber as the data type.
FILTERING
Filtering refers to sieving out particular records from the database. The records you
sieve out can be printed, deleted or edited separately. There are three types of filters in
Access.
Filter by Selection:- This filter allows you to choose a criteria/condition for sieving out
records by selecting them directly from the table in datasheet view.
Steps:
- Open the table in datasheet view
- Highlight the cell that contains the criteria that you need e.g. Under First Name,
highlight Philip.
- Move to Records menu, select Filter, then Filter by Selection or select the Filter
by Selection button on the Standard toolbar.
Access displays all the records that meet the criteria e.g. all people in the database
whose first names are Philip.
- To remove the filter and get back the original table, move to Records menu
and select Remove Filter/Sort, or click the Remove Filter button on the
Standard toolbar
You can also use the following methods:
- Select the first character of a name to find all names that begin with that character.
- Select the last character of a name to find all names that end in that character.
- Select any character inside a name to find all names that contain that character.
- Click twice inside a Yes/No field find True of False respectively
Note:- You can use Filter Excluding selection from the same menu to sieve out all the
records that do not meet the selected condition.
Filter by Form:
This filter opens up a form where you can give more elaborate criteria.
Open the table
Move to Records menu, select Filter, then Filter by Form, or click the Filter by Form
button on the Standard toolbar.
A form will appear where you can type in or choose the criteria you want
Choose Clear Grid from Edit menu to remove any condition that might have been used
previously
Type you condition within the appropriate field e.g. to list all people called Philip, click
under Firstname, then type in ‘Philip’- or click inside that field and choose it from the
dropdown list.
Choose Apply Filter/Sort from Filter menu or click on the Apply Filter button on the
Standard toolbar.
Choose Remove Filter/Sort from Records menu to recover the original table.
The following can also be used:
Fname Lname
Peterson Kirui It will look for a person called Peterson Kamau.
Names
K* Will filter all records of people whose names begin with K.
*E* Will filter all records of people whose names contain letter E.
*A Will filter all records of people whose names end with letter A.
Age
>18 It will display all people with age of above 18.
Between 25 and 30It will display records of all people aged between 25 and 30.
>=25 and <=30 It will display records of all people aged between 25 and 30
Country
In(Uganda, Kenya) Displays people from Uganda or Kenya
Uganda or Kenya Displays people from Uganda or Kenya
Date
>74/10/31 It displays all records on the specified date and after it
Between 90/10/31 and 95/7/1 Displays records between the indicated dates.
Awards
Is Null Displays all records given the award ‘Null’.
Is Not Null Displays records that don’t have the award Null.
Sports
Like *ball Displays all records with all sorts of ball games.
Not Football Displays all records of people who don’t play football.
Date of Birth
Date ( )-30 Displays all records of people born 30 days ago.
Between Date ( ) and Date ( ) – 30 All records of people born within the last 30
days.
You can also combine more than one condition.
Advanced Filter/Sort
The above filter allows one to sort and filter records at the same time.
Open the table
Move to Records menu, select Filter then Advanced Filter/Sort
Access will take you to QBE grid, from this grid you have a field list in the top half and
the grid table.
The grid table allows one to choose fields for sorting/filtering.
Double click the field from the field list or click once in the Field Name row within the
grid and select the field name from the dropdown list.
Type your condition within the Criteria row under the correct field
Choose the sorting order, if any, within the Sort row under the correct field.
Choose Apply Filter/Sort from Filter menu or click on the Apply Filter button on the
Standard toolbar.
Choose Remove Filter/Sort from Records menu to recover the original table.
You can insert as many fields as you may want to sort on or specify criteria in.
You can also combine several conditions using AND or using OR;
To combine with AND, type the conditions within the same row but under the correct
field names.
To combine with OR, type the conditions in different rows but under the correct
fieldnames.
NB: For a YES/NO field you can use NO/OFF/FALSE/0 for a false condition and
YES/ON/TRUE/-1 for a true condition.
The criteria that was previously used stays in effect until you delete it from the QBE grid
so remember to choose Clear Grid from Edit menu every time you want a new criteria.
Renaming a table:
Open the database file
Select the table name
Click the table name, or right-click the table name, or choose Rename from Edit
menu within the Objects window
Type in the new name and click anywhere outside that name
Deleting a table
Open the database file
Select the table name
Press Delete key, or choose Delete from Edit , or right-click the table name and
choose Delete.
Click yes to confirm
Moving a table
Select the table name
Choose Cut from Edit menu, or click the Cut button on the Standard toolbar, or right-
click the table name and choose Cut from the displayed menu.
Close the file
Copying a table
A table can be copied within the same file or to a different file. If you copying a table
within the same file, the copy must be given a different name but if you are copying a
table to a different file, you can use the same name or change the name.
Copying within the same file
Select the table name
Choose Copy from Edit menu, or click the Copy button on the Standard toolbar, or
right-click the table name and choose Copy from the displayed menu, or press
Ctrl+C
Choose Paste from Edit menu, or click the Paste button on the Standard toolbar.
In the next dialog box, type a new name, choose ‘Structure and Data’ then click Ok.
Copying to a different file
Select the table name
Choose Copy from Edit menu, or click the Copy button on the Standard toolbar, or
right-click the table name and choose Copy from the displayed menu.
Close the file
Open the file you want to copy the table to
Choose Paste from Edit menu, or click the Paste button on the Standard toolbar.
In the next dialog box, type the table name, choose ‘Structure and Data’ then click
Ok.
Paste Options
There are three options that appear within the Paste dialog box whenever you are
copying or moving tables namely:
i) Structure Only – This copies/moves the structure of the table (Fieldnames) only
ii) Structure and Data – This copies/moves the structure and data (fieldnames and
records).
iii) Append Data to Existing Table – This copies/appends only the records to an
existing table with similar fieldnames. Type the name of the existing table within the
Table name box
original file as an independent entity. I.e. Once you import, the new imported table will
have nothing to do with its source.
When you link tables/data, Access maintains a connection between the source and the
new table. Any changes you make to the source will be reflected in the new table and
some properties of the table cannot be changed from Access but only from the original
table/data. I.e. the linked table remains dependent on the original data.
Linking a table/data
Open the database file in Access
Click on the Tables button
Select Get External data-Link Tables from File menu, or click the New button on the
right edge and choose Link Table from the next dialog box.
In the Link dialog box that appears, Select the type of files under ‘Files of type’ e.g.
Microsoft Excel, choose the location (drive or folder) under ‘Look In’ and select the
filename from the displayed list of files.
Click on Link
Within the Link wizard that appears, answer the questions correctly one by one as
you click on Next to move to the next step until you finish.
E.g.
Choose the worksheet that contains the data and click Next
Choose ‘First Row Contains Column Headings’ and click Next
Type the table name and click Finish.
Click Ok to complete the link
The linked worksheet/data will maintain the icon of Excel.
EXPORTING DATA
Open the database file in Access
Select the table you want to export and choose Save As/Export from File menu, or
right-click the table and choose Save As/Export from the displayed menu.
Choose ‘To an External File or Database’ within the next dialog box and click Ok.
In the Save Table dialog box that appears, Select the type of files under ‘Save as
type’ e.g. Microsoft Excel 97, choose the location (drive or folder) under ‘Look In’
and select the name of the file you want to export the table to.
Click on Export
The exported table appears in Excel as anew worksheet within the file it has been
exported to.
FIELD PROPERTIES
These are some effects/features or conditions you can apply to different data types to
control the data that can be entered within specific fields.
Most of them should be specified before you type any records within the table but some
of them can still be changed even after keeping records in a table.
Different data types have different field properties. They are all specified within the
Design view of a table. The tables design view is divided into two parts:
The upper part is used for typing field names, specifying data types and putting field
description if any.
The lower part is used for displaying and assigning field properties to selected fields.
Each data type has a different set of properties.
You have to position the cursor within the field you want to affect.
These properties include:
Caption:- This lets you define/type an alternative fieldname to be used in datasheet
view and as labels in tables, forms and reports. They provide a neat and descriptive
name since the fieldname should be kept small for practical use.
Format:- This allows you to determine the way data appears in a field. The formats
include Currency, Fixed, General, Percent, Scientific, General data, Medium date,
Medium time. E.g.
You can change the date or time format to affect the way dates and time will be
displayed within the table.
You can also choose Fixed format for numbers then specify the number of decimal
places to appear automatically next to the numbers as you type them.
Decimal places:- It is used to define an automatic number of decimal places to appear
in values. The option will only work on value fields that already have the Fixed format.
Default Value:- Lets you define a value/label that will automatically be inserted in the
field as you add new records. If it is a label, it must be enclosed in double quotes.
E.g. You could use it in an Address field to insert the text “P.O. Box” automatically as
you enter records within the Address field
The default value affects only new records inserted after setting it.
Field Size:- Lets you specify the maximum number of characters you can type within a
field. It only works for text and number fields. The sizes available for numeric fields
are; Byte (range 0 to 25), Integer (range 32768 to +32768), Long integer (range -
2,147,483 to +2, 147,482). The default for a text field is 50 and the maximum you can
set is 255 characters. It must set before typing records within the table.
Input Mask:- Lets you define a pre-formatted pattern for the entry of data into a date or
a text field. The data in that field must conform to the specified pattern. It works almost
like the filed size property but it uses a pattern instead of a number and when both of
them are used it is given the first priority.
It uses letter a/A (small or capital) to represent the number of characters you can enter
in a field.
A small a specifies the maximum number of characters you can enter in a field while a
capital A specifies the exact number of characters that must be entered within that field.
A greater than symbol > at the beginning of the pattern converts the text to capital
letters while a less than symbol< converts all the entries in that field to small letters.
Examples of patterns include: -
0#/0#/0# - This forces a two-digits entries for the year, month and date in a date field.
AAAAAA – You must type six characters in that field.
aaaaaa:- You can type six or less characters in that field.
A and a:- Act as place holders; i.e. They control the number of characters entered into a
field.
>aaaaa:- All the text will appear in capital letters but they can be five characters or less.
>AAAAA:- All the text will appear in capital letters and they must be five characters.
<aaaaa:- All the text will appear in small letters but they can be five characters or less.
<AAAAA:- All the text will appear in small letters and they must be five characters.
> &< symbols work hand in hand with the ‘A’ and ‘a’ place holders i.e. they can’t work
on their own.
Required:- This can be set to Yes or No. When this option is on (YES) an entry must be
made within that field and vice versa i.e. that field cannot be left blank when entering
records.
Validation Rule:- Lets you create an expression/formula that test data as it is entered
into the field. It automatically rejects faulty entries e.g. entering very large or very small
figures in the Age or Salary fields.
E.g. To limit an age field from 18 to 55 type Between 18 and 55, or >=15 and <=55
An error message will then appear any time you enter a value prohibited by that rule.
>=Date( ):- Will allow entries whose dates are the current date or later.
<=Date( ):- Will allow the current date or before
Country:-
>Kenya:- Allows entry for any country starting with K to Z
Validation Text:- This is the error text/message that will be displayed when the
validation rule is broken. It allows one to type an alternative error message that will
appear whenever you enter a value prohibited by the validation rule above. You can put
in a useful message that can be clearly understood by the input clerk e.g. wrong value.
Indexed: - Indexing is the process of arranging records alphabetically, numerically or
chronologically in the ascending order only.
This property can be set to three different options namely:
No – Use this if you don’t want your records to be sorted on this field.
Yes (Duplicate Ok)- Automatically sorts the records on that field in the ascending order
and allows duplicates.
Yes (No Duplicates) - Automatically sorts the records on that field in the ascending
order but does not allow duplicates.
QUERRIES
A query is simply a group of records that have been filtered from an original table and
stored separately but still dependent on the table.
You use queries to view, change, and analyze data in different ways. You can also use
them as the source of records for forms and reports.
By using a query, you can narrow down your database table and sieve out specific
information for printing, viewing, editing or saving.
A query can be used to:
i) Bring together data from multiple tables and sort it in a particular order
ii) Perform calculations on groups of records
iii) Create a new field for combining the contents of several fields together and even
to add new labels/data to the contents of existing fields
iv) Calculate a sum, count or another type of total and then group the results by two
types of information – one down the left side of the datasheet and another one
across the top i.e. it can create a brief summary of records (totals query)
SELECT QUERIES
It is a passive query that lists information in a table calling to certain field or criteria.
They are similar to filters but:-
Can allow you to choose a field to show or hide
Allows one to create calculated fields
Allows you to query more than one table at a time (join tables).
Allows one to create a totals query for a summary
Combining Tables
You can combine tables from the same database provided that the tables have a
common field.
The common field should have the same name, data type and information arranged in
the same order.
E.g. If the common field is Names, it must appear in both tables and its contents must
all be similar and arranged the same way in both tables.
- From the database window, choose Query tab
- Click on New then Design view
- From the Show table dialog box, select all the tables you want to join one by one as
you click on Add and then click Close.
- In the QBE grid, both/all tables should appear in the table area.
- Click on the common field from one table and drag to the common field of the other
table. A link line appears between the two.
If you right click this line, you can delete the join or you can change the join properties.
- Once the tables are joined, insert the fields into the gird as usual.
You will able to choose fields from both tables and arrange them, as you desire.
The common field should only be selected once since its contents are similar in both
tables.
You can as well specify any criteria and any sorting order.
- Type the first parameter exactly as you have entered it in the criteria cell except
without square brackets e.g. which country do you want?
- In the next column choose the data type for the parameter according to the filed you
are using e.g. Text. It should match the data type of the field where the criteria is.
- Repeat steps 4 & 5 for other parameters, if any.
When you run your query, the same text will appear and you will type your condition
within the provided area.
Steps:
- In Query design view, choose the table you want to use in your cross tabs.
- Choose Crosstab Query from the Query menu or from the Query Type button.
- Choose the two fields you want to group on, one by one e.g. Country and City
- Choose the Value field that you want to calculate
- On the Total row, select what you want to calculate under the Value field e.g. Sum,
Average, Max, Min, Count etc.
- Under Crosstab row, specify the Row Heading and the Column Heading under the
two fields for grouping appropriately and under the value field, choose Value.
- Run your query to view the summary.
NB: You can use more than one Row Heading but there should only be one
Column Heading and one Value field.
ACTION QUERY
These are queries that make changes to many records in just one operation. There are
four types of Action queries namely:-
Delete Query
Update Query
Make Table Query
Append Query
These queries don’t need to be saved because after they are run, the changes are
permanently made within the tables.
Delete Query
Deletes a group of records from one or more tables at once. E.g. you could use a
delete query to remove products that are discontinued or for which there are no orders.
It is faster to use a delete query than to delete each record separately.
Syntax:
- Create a new query that contains the table from which you want to delete records.
- Click on Query type button on the standard toolbar and then select Delete Query, or
choose it from Query menu.
The delete row is then added to the grid.
- From the table which you want to delete records, drag the (*) asterisk from the field
list to the query design grid (put it inside the first column under field.)
The word “From” appears in the delete cell, this indicates that the values/records
deleted will be from the table specified.
- In the next column, specify the fieldname and the criteria for the records to be
deleted.
“Where” appears in the delete cell within that column.
- Choose Datasheet View from View menu to view the records that will be deleted
first to ensure that you are not deleting the wrong records.
- Change back to Design view
- Run the Query.
A warning/confirmation message then appears.
- Click on “YES” to complete the action.
You don’t need to save the query since after running it the changes are permanently
made within the table.
You have to open the table to view the changes that have been made.
Update Query
This query makes global changes to a group of records in one or more tables. E.g. you
can raise prices by 10% for all dairy products or you can raise salaries by 5% of people
within a certain job category.
You can also use it to add some new labels/characters within records e.g. adding the
title “Dr. “ at the beginning of all FNames within a table.
Syntax:
- Create a new query in design view.
- Select the table in which you want to update records.
It should contain the fields you want to use for setting the criteria
- Choose Update Query from Query menu or from the Query Type button
The ‘Update to’ row is then added to the grid.
- Add the field(s) you want to update to the query design grid by double clicking on the
it/them.
- In the “Update to” row type in the expression/formula that you will use to update
information in your table for each field(s) appropriately
- Give any condition if need be.
You can’t update a field more than once within the same query.
To see a preview of the records to be updated– click the Datasheet view button on the
standard toolbar.
WHY?: Because once you update the records you cannot reverse the action.
Switch back to design view.
Run the query and click “Yes” after the warning that will appear.
Don’t run the query again because if you do, it will keep on making the same changes
every time you run it.
Examples:
To increase the values under Age by 1, write [age]+1 within the ‘Update to’ row under
Age field.
To increase the Salary by 20%, write [SALARY]+20/100*[SALARY] or
120/100*[SALARY] within the ‘Update to’ row under Salary field.
To add the title “Dr. “ at the beginning of Names, write “DR. “ & [NAMES] within
the ‘Update to’ row under Names field.
Append Query
It adds/copies a group of records from one or more tables to the end, or at the bottom of
an exiting table.
Append query appends data in the matching fields and ignores the others.
Data can only be appended within tables that have similar field names or data types e.g.
the contents of Names can be copied from one table to another table with the same
fieldname.
Syntax:
Create a query that contains the table whose records you want to append to another
table.
In Query design view, click 'Query type' button and select "Append Query".
The Append window appears
In the table name box type/choose the name of the table you want to append records to.
Select the table from the dropdown list, click 'Current database' to put the query results
to a table in the currently opened database.
Incase another database is to be used, enter the table name, click "Another
database" option and type the name of the database file.
Click OK.
Double click on the fields you want to append from, from the field list one by one.
The fields should include the ones for setting criteria and the primary key fields, if any.
The fieldnames that the records will be appended to will appear automatically within the
‘Append to’ row if the fieldnames are similar, otherwise you have to click as you
choose the fieldnames to append to one by one.
View the records to verify the results before running the Query.
Change back to Design view
Run the Query and click YES to confirm.
FORMS
A form offers a presentable and a more flexible way to view and work with data in a
table. Unlike datasheet view, which displays data in rows and columns, forms displays
data in a variety of formats (some created by the user).
You can still add new records, delete records and edit records within the form
A from is used to:
1. Display only the information that the designer of the form wants to see.
2. To view records as well as input new records. Calculated fields can then be
developed.
3. It allows a user to apply different formats for the fieldnames and the records
4. It allows user to present data in different styles/layouts e.g. tabular, columnar etc.
Forms can be created from Design view, using the AutoForms (Columnar, Tabular etc)
and by using the Form Wizard.
Forms can be created from Tables or from Queries and they can share the same names
as the queries or as the tables.
When using a form, use the Status bar for record navigation.
Use the New records button to insert records into your database and use the delete
button (Records) to get rid of records.
Bound Controls:- They have their data sources in a field from a table or query. They
can be used to input values, dates or numbers into the database.
Unbound Controls:- They do not have data sources, they can be used to display text,
lines, boxes and pictures.
Calculated Controls:- These are expressions as their data sources. They can be used
to display calculated values as a result of data entry. An expression is a statement
written down that gives specific results after evaluation e.g. to get the average of three
tests; you can use =([Dos]+[Windows]+[Word])/3
=[Salary]*1.1 - To calculate a salary increment of 10%
Each expression must start with an equal sign (=).
AVAILABLE TOOLS/CONTROLS
There are several controls used in forms. The controls can be bound or unbound and if
they are bound, they will be from underlined table or query. For bound controls, the
type of objects placed on the forms depend on the display control properties from the
look up tab of the table structure.
The controls are: -
Labels: - These are unbound controls that display descriptive text such as titles,
captions, long fieldnames or even instructions. Most labels are attached to other
controls. When creating a label;
You can break a line by pressing Ctrl + Enter
Text Box: - This control allows you to enter text into your form. This text can be used
for an event or a field entry. A text box can also be a calculated control containing a
valid expression (=). The expression can be typed in directly into the text box or by
following these steps: -
Click on the control
Select the Property sheet from View menu
Click on Data tab
Type the expression under Control Source
If you make a text box for a memo field, you can increase the size of a text box then add
scrollbars to it.
Select the text box.
Select Properties from View menu
On Format tab, under Scroll bars choose Vertical.
Check Box: - (Toggle, Option, ….)These three controls are primarily used in YES/NO
field. When Unbound they can be used in decision making in dialogue boxes.
List Box: - It creates a control to give a list of choices and for data entries into a certain
field. To use a list box, make sure that the control wizard is on (from the toolbox).
Select the tool and drag its dimensions on form.
The wizard asks you: how you want the list box to get its values – choose “I will type the
values that I want”; Asks you the number of columns you want the list box to display
and the different entries you want listed.
Click in the grid, type them pressing tab after each.; Where you want to store that
information – select “Store that value in this field”, then choose a field from the list.;
Asks for a label for the control.
Combo box: - It is a combination of a text box and a list box; saves space within the
form. Follow the same steps as when creating a list box.
Command buttons: - Creates a control that can be assigned to a proceeding event.
Examples: Okay & Cancel button in dialogue boxes.
Make sure the control wizard is on, before creating command button.
Image control: - It inserts pictures into the form (unbound)
Bound objects: - It inserts bound control that can be used to display the contents of an
OLE object.
Drawing tools: - Used for drawing objects.
Property Sheet
You can use it to view and change the properties of a selected control. The properties
depend on the data type of that field. To open the property sheet:
Right click a control then choose properties or select properties from View menu.
The basic tabs found on the sheet are:
Locking a field
You can lock a field so that its contents do not change when editing data in a table.
Select the control that has that field.
Open the property sheet and select data tab.
Click on Locked then choose ‘YES’ from the drop-down list.
FORM SECTIONS
Every form is divided into five parts:
Details: - To show the field from an underlined table or query.
Form Header: - Appears at the top of the form for page one only.
Form Footer: - Appears at the bottom of the form for the last page only.
Page Header: - Appears at the top of each page but it is not visible from form view.
Page Footer: - Appears at the bottom of each page but it is not visible from form view.
To see the effects of different controls in different sections, use print preview.
NB:
Page Header/Footer will only appear in print preview while the Form Header/Footer will
appear both in Form view and in Print preview.
In Design view you only be able to see the Page-number and the date and tine markers
or placeholders.
CHARTS
You can easily create a chart from the database table by following this syntax:
From the database window, click on Form tab.
Click on New, then select Chart wizard
Select the table or query for your chart
Access’ chart wizard asks you which fields you want in the chart (add them to the list
and click on ‘NEXT’).
Select the chart type you want, ‘NEXT’.
Preview your chart from the Preview chart button, ‘NEXT’.
Enter the title for your charts, choose whether you want a legend or not, ‘FINISH’.
The chart is inserted as an object onto the form.
REPORTS
Report is used to summarize the contents of a database. It could summarize a table or
a Query, and make it presentable and easy to understand.
Reports allow one to group data together and create SubTotals (Mathematical
summaries for groups.)
These calculations can include Average, Sum, Max, Min etc.
If you have a table or a query that has Stock Records, you can group it according to the
order date field and summarize using sum on the buying price, selling price, and profit
fields.
If you had a table or a query with students grade, you could group the table according
the grades, summarize using the count to find out how many students scored a
particular grade.
Using AutoReport.
This option does allow you specify any grouping fields and the value fields to be
calculated. It creates a report that is more less like a form.
- Select Reports from the Database objects window
- Click on New
- Choose AutoReport: Columnar or AutoReport: Tabular
- Choose the table or the query that contains the records.
- Click Ok
Report section
One of the main differences between reports and forms is the ability of reports to group
database records.
The report has got an extra grouping section; the sections are as follows:
Report header : Appears at the top of the report on the cover/first page only.
Page header : Appears at the top of each page
Group header; Appears at the top of each group, it normally displays the group name
e.g. Grade.
It prints once for each record.
Group footer: Appears at the bottom of each group, It shows the summary totals e.g.
Total fee =sum([fee])and Average AGR =Avg([age])
Page footer: Appears at the bottom of each page e.g. =NOW ( ) , "page " and " page "
Report footer : Appear at the end of the report, can be used to display grand totals.
Each group is available from the Design view.
GROUPING DATA
You can create or remove grouping and sorting fields by clicking on ,Sorting and
Grouping, from the view menu or by clicking the icon from the toolbar within the report
design view.
A dialogue box appears where you can select the field to group by and give a sort order.
The group properties within the dialogue box are:
1 The group header ; - set it to " YES " if you want it.
2 The group footer : - """""""""""""""""""""""""""
3 The group on: : used to choose how you want to form the groups.