You are on page 1of 28

Topic 3.

Working with
Tables
MS Access
3.1. Records
• Add, delete records in a table:
• On the left side of the table there is a small * symbol. This
symbol represents the record (row) currently selected.
• As more records are entered into the table or as you navigate
through the table, this symbol will provide a confirmation of the
exact row you or your pointer is in.

Prepared by Mr. Patrick Okot


Add records
• To the right of the * symbol, New is displayed just below the ID
field name, signifying this row represents a new record.
• Data cannot be typed into this column, as by default this is an ID
column with an AutoNumber Data Type.
• NOTE: The AutoNumber Data Type automatically generates a
unique, sequential number for each new record entered so data
entry into this field is restricted.
Prepared by Mr. Patrick Okot
Deleting a Record
• Occasionally you may need to remove a record from a table.
• Move the pointer to the column, left of the ID field. When the
pointer changes to a right pointing arrow, click to highlight the
whole row (record).
• With the pointer anywhere within the highlighted area, click using
the right mouse button to activate the shortcut menu.

Prepared by Mr. Patrick Okot


Delete …
• Click on the Delete Record option. • A warning is displayed:

• NOTE: Undo is not available when deleting


records, therefore any deletions will be committed.
• Click on the Yes button to confirm the deletion.

Prepared by Mr. Patrick Okot


Deleting multiple records
• If a group of records needs to be deleted, the process is similar to
deleting a single record. The only difference is in selecting the records.
• Move the pointer left to the row selection column. Locate the first
record in the group and with the right pointing arrow displayed, click
and drag down to create a highlighted block of records.
• Delete all records in the same way as shown in the previous section
describing how to delete a single record.
Prepared by Mr. Patrick Okot
Add, modify, delete data in a record.
• To add data simply click on the box you need to add data and
start typing.
• For modifying data the same click on the box that you need to
change, place your cursor before or after that word, and type what
you need.
• To delete data, select the box that you need to delete and press
delete from your keyboard
Prepared by Mr. Patrick Okot
3.2. Table Design
• Create and name a table and specify fields with their data
types like: text, number, date/time, yes/no:
• Click on Create.
• Then click on Table from the tables section.
• Click on the arrow in the view section and choose
• Design view button

Prepared by Mr. Patrick Okot


Create table …
• Name the table

• Start typing the field names and for


each field name choose the data type
like text, number, date/time, yes/no
etc.

Prepared by Mr. Patrick Okot


Prepared by Mr. Patrick Okot
Apply field property settings: field size,
number format, date/time format, default
value.
• It’s important that to apply field properties such as field size etc. you
need to be in design view.
• After choosing the data type at the bottom you will have a tab called
General. From there you can modify the field size, number format,
date/time format, default value. But the General tab will change
according to the data type chosen.
• For the field size and default value just input the number that you
need.
Prepared by Mr. Patrick Okot
Field properties …

Prepared by Mr. Patrick Okot


Create a validation rule for number,
date/time, currency
• Microsoft Access provides a variety of ways to control how users
enter data into your database.
• For example, you can limit the data that a user can enter into a
field by defining a validation rule for that field.
• If the data that a user enters into the field breaks the rule, Access
will display a message telling the user what kind of entries are
allowed.
Prepared by Mr. Patrick Okot
Create validation rules for number fields

• Let’s say you have a table with the following fields:

• You may need to set a validation rule on the result field restricting the
numbers entered in this field to be not greater than 100. This will avoid
mistakes, such as pressing an extra number while keying in results.

Prepared by Mr. Patrick Okot


Validation …
• To do this, follow the steps below:
• Click on the Exam Result field
• In the General Tab, click in the box provided for validation rule
• Type: <=100
• This means that only values which are less than or equal to 100 will be
allowed to be keyed in.

Prepared by Mr. Patrick Okot


Validation …
• Similarly, in any number field we can use the below symbols for
creating validation rules:

Prepared by Mr. Patrick Okot


Create validation rules for date fields
• You might have a table that contains a field with date as the data
type. It might also be the case that you wish to restrict the dates
that can be entered in that particular field.
• Let’s say we have a database of a club, where only adults that were
born from 1970-1980 can register.
• In the validation rule for the date of birth field we can type:
Between 01/01/1970 and 31/12/1980
Prepared by Mr. Patrick Okot
Date fields …
• We can also use the mathematical symbols discussed earlier on
with dates.
• For example, if you only wish to allow users that were born
before 1990, you can enter one of the following validation rules:
• <01/01/1990
• Or
• <=31/12/1989

Prepared by Mr. Patrick Okot


Understand consequences of changing
data types, field properties in a table
• When changing data types or field properties in a table data could
be lost as it will not match with the types you had entered.
• Be consistent in data types when making changes.

Prepared by Mr. Patrick Okot


Set a field as a primary key
• Click on the field that you wish to set as a primary key. Click
Primary key which is in the Design tab in the tools section. A
key will appear at the left of the field name.

Prepared by Mr. Patrick Okot


Prepared by Mr. Patrick Okot
Deleting a Primary Key
• In the Design view of the table right click on the field from which
you want to remove the primary key setting.
• Click Primary Key.
• You will notice that the key symbol will no longer be displayed in
the record selector.

Prepared by Mr. Patrick Okot


Index a field (with, without duplicates
allowed)
• Your primary key field will automatically be indexed so that
duplicated entries are not allowed. However, you might need to
index other fields in your table.
• In the General section of the Design view of the table click in
the Indexed box and then click on the drop down arrow.
• You can set the index to allow or not to allow duplicate records:
Prepared by Mr. Patrick Okot
Indexed …

Prepared by Mr. Patrick Okot


Add a field to an existing table
• To add a field to an existing table:-
• Open the table
• Go to Design View
• Go below the last Field Name and type the field name you wish to add
• Add also the data type and Save

Prepared by Mr. Patrick Okot


Change width of columns in a table
• Open a table in Datasheet view.
• To resize a column:
• Do one of the following:
• To resize a column to a specific width, position the pointer on the right
edge of the column you want to resize, as shown in the illustration and
drag until the column is the desired size.
• To size a column to fit its data, double-click the right edge of the column
heading.
Prepared by Mr. Patrick Okot
Width …
• Note: You can't undo changes to the
width of columns using the Undo
command on the
• Edit menu. To undo changes, close the
datasheet, and then click No when
asked if you
• want to save changes to the layout of
the datasheet. This will also undo any
other layout
• changes you have made.
Prepared by Mr. Patrick Okot
Chapter Exercise

Prepared by Mr. Patrick Okot

You might also like