Part III Ms Access Lecture Notes
Part III Ms Access Lecture Notes
3.2 Introduction
MS Access is a database management software. It is a software that allows you to organise, store
and retrieve large amount of information quickly and efficiently.
The collection of data is managed by computer method of the organisation. Access consists of three
important elements:
Data collection: the necessary data is gathered and recorded on a form called a source document that
serves as input to the system for example data describing a student entered on a course registration
form.
Verification: the data is edited in some manner to verify its accuracy; perhaps the data entry operation
visually verifies the data as it is displayed on the screen. Any errors are in this corrected.
Security: while the data exists in storage, it is kept secured to prevent destruction, damage or
misuse.
Organization: the data can be arranged in various sequences to increase its information value.
a. Subject: Determine the purpose of the database, i.e. what information you wish to store is all
about. All the information will be stored in one convenient place, and that is your database.
This is similar to a filing cabinet.
b. Topic: Determine the various topics related to the subject above. Information about each topic
will be stored in a separate table (file) within the database. This is like a shelf in a filing
cabinet.
c. Sections: Decide on the various sections (fields) of each topic. What different attributes of
the topic will be stored in each table? This is like a drawer of a particular cabinet.
d. Relations: Determine the relationship between information. Which of the various topics
(Tables) have relationship with others. Look at each table and decide how the data in each
table is related to the data in other tables in the database. Do any of the topics make reference
to other ones? If yes, it means the topics are related.
Creating Table
Using Microsoft Access, you can manage all your information from a single database file. Within the
file, divide your data into separate storage containers called tables; view, add, and update table data
by using online forms; find and retrieve just the data you want by using queries; and analyze or print
data in a specific layout by using reports. Allow users to view, update, or analyze the database‟s data
from the internet or intranet by creating data access pages.
To make data available on the internet or an intranet for interactive reporting, data entry, or data
analysis, use a data access page. Microsoft Access retrieves the data from one or more tables and
displays it on the screen within the layout you choose in the page Wizard, or a layout that you create
from scratch. Users can interact with the data by using features on the data access page.
A table is a collection of data about a specific topic, such as product or customers. Using a separate
table for each topic means that you store that data only once, which makes your database more
efficient, and reduce data entry errors.
Tables organize data into columns (fields) and rows (records).
In table Design View, you can create an entire table from scratch, or add, delete or customize the
fields in an existing table.
In table Datasheet View, you can add, edit, view, or otherwise work within the data in a table. You
can also display records from tables that are related to the current table by displaying sub datasheets
within the main datasheet. With some restrictions, you can work with the data in sub datasheets in
many of the same ways that you work with data in the main datasheet.
3.9 Table
The table is the area in Access that enables you to customize or determine how your Database would
be structured or structure that holds the data relating to specific topic. The table provides a means of
categorizing the different aspects of the information to be stored in the database. In actual fact, it is
the starting point of using the Access.
You can use the Data Type property to specify the type of data stored in a table filed. Each field
can store data consisting of only a single data type.
Setting
Lookup Wizard Create a field that allows you to choose a The same size as the primary
value from another table or from a list of key field used to perform the
values by using a list box or combo box. lookup, typically 4 bytes.
Clicking this option starts the Lookup
Wizard, which creates a Lookup field.
After you complete the Wizard,
Microsoft Access sets the data type
based on the values selected in the
wizard.
3.10.1 Index
A feature that speeds up searching and sorting in a table based on key values and can enforce
uniqueness on the rows in a table. The primary key of a table is automatically indexed. Some fields
cannot be indexed because of their data type.
You can use special symbols in the setting for the Format property to create custom formats for
Text and Memo fields.
Setting
You can create custom text and memo formats by using the following symbols.
Symbol Description
@ Text character (either a character or space) is required
& Text character is not required
< Force all characters to lowercase
> Force all characters to uppercase
You can set the Format property to predefined number formats or custom number formats for the
Number and Currency data types.
Setting
Predefined Formats
Setting Description
General Number (Default) Display the number as entered
Currency Use the thousand separator; follow the settings specified in Regional
Settings in Windows Control Panel for negative amounts, decimal and
currency symbols, and decimal places
Euro Use the currency format, with the Euro symbol (), regardless of the
currency symbol specified in Regional Settings in Windows Control
Panel
Fixed Displays at least one digit; follow the settings specified in Regional
Settings in Windows Control Panel for negative amounts, decimal and
currency symbols, and decimal places.
Standard Use the thousand separator; follow the settings specified in Regional
Settings in Windows Control Panel for negative amounts, decimal
symbol, and decimal places
Percent Multiply the value by 100 and append a percentage sign (%); follow the
settings specified in Regional Settings in Windows Control Panel for
negative amounts, decimal symbols and decimal places
Scientific Use standard notation
You can set the Format property to predefined date and time formats or use custom formats for the
Date/Time data type.
Setting
Predefined Formats
The following table shows the predefined Format property settings for the Data/Type.
Setting Description
General Date (Default) If the value is a date only, no time is displayed; if the value is
a time only, no date is displayed. This setting is a combination of the
Short Date and Long Time settings.
Warning: The Short Date setting assumes that dates between 1/1/00
and 12/3/29 are twenty-first century dates (i.e. the years are assumed to
be 2000 to 2029). Dates between 1/1/30 and 12/31/99 are assumed to
be twentieth century dates (i.e. the years are assumed to be 1930 to
1999).
Long Time Same as the setting on the Time tab in the Regional Settings
Properties dialog box in Windows Control Panel.
Example: 5:34:23 PM
Medium Time Example: 5:34 PM
Short Time Example: 17:34
Setting
Microsoft Access uses a check box control as the default control for the Yes/No data type. Predefined
and custom formats are ignored when a check box control is used. Therefore, these formats apply to
data that is displayed in a textbox control.
Predefined Formats
The Format property provides the Yes/No, True /false, and On/Off predefined formats. Yes, True,
and On are equivalent, as are No, False, and Off. If you specify one predefined format and then enter
an equivalent value, the predefined format of equivalent value will be displayed. For example, if you
enter True or On in a textbox control with its Format property set to Yes/No, the value is automatically
converted to Yes.
Custom Formats
The Yes/No data type can use custom formats containing up to three sections.
Section Description
First This section has no effect on the Yes/No data type. However, a
semicolon (;) is required as a placeholder.
Second The text to display in place of Yes, True, or On value
Third The text to display in place of No, False, or Off values
3.11.1 Validation
(i) Text: The default data, stores text or combination of text and numbers, as well as numbers that
require calculations, as well as a specific format. E.g. Names, Address, Sex, Region, Title etc.
(ii) Number: Numeric data used in mathematical calculations. Store numbers from 0 to 9 and symbols
considered to be numeric symbols. E.g.. Telephone Number, *, +, -, /,
(iii)Memo: Stores lengthy text or combinations of numbers and text.
(iv) Date/Time: Date and Time values for the years as validated in the format. E.g. Date of Birth,
Date to be paid etc
(v) Currency: Values and numeric data used in mathematical calculations in, e.g. Total, Outstanding
balance, Credit Limit etc
(vi) Auto Number: A unique random number assign by MS-Access whenever a new record is added
to the table. Auto Number fields cannot be updated
(vii) Yes/No: Values and fields that contain only one of two values (Yes or No, True or False)
(viii) Look-Up Wizard: Enables you to store records that would be used (Male or Female)
(ix) OLE: Enables you to store pictures or signatures
Data Types
Description
This provides detailed explanations of the field you have provided within the fields (e.g. Student
Name). This internal documentation is necessary to make it easier for the User to understand and
make modification. This is optional, though.
Validation
This means rules to check for the correctness of data entry, setting Fields Properties helps you to
validate for the data entry for each field created. The data type selected for the field determines the
properties you can set for that field.
3.12 Verification
This is to ensure that right data are entered at the right place
Process
a. From the table view, select the field and then select the data type
b. Select filed property from below
c. Make your validation
Property Description
Field Size The maximum length of the text including spaces
Format How data is to be displayed. It could be in the predefined Formats or
customized one by yourself
Decimal Places Number of decimal places
Input Masks Formatting characters for the data type
Caption Default field table in a form or report
Default Value Value entered in a field when records are created
Validation Rule An expression that defines data entry rules for the record e.g.
>=#5/24/2001# And <=#5/24/2010# (date)
Validation Text Text that appears when an invalid data is entered
Required Setting that defines whether data must be entered
Index Single field indexes to speed searches and sorting.
Field Properties
3.13 Primary Key
One or more fields whose value or values uniquely identify each record in a table. In a relationship,
a primary key is used to refer to specific records in one table. The primary key is called a foreign key
when it is referred to form another table.
The power of a relational database system such as MS Access comes from its ability to quickly find
and bring together information stored in separate tables using queries, forms, and reports. In order to
do this, each table should include a field or set of fields that uniquely identifies each record stored in
the table. This information is called the primary key of the table. Once you designate a
primary key for a table, to ensure uniqueness, MS Access will prevent any duplicate or Null values
from being entered in a primary key field.
There are three kinds of primary keys that can be defined in MS Access: AutoNumber, Single-field,
and Multiple-field.
An AutoNumber field can be set to automatically enter a sequential number as each record is added
to the table. Designating such a field as the primary key for the table is the simplest way to create a
primary key. If you do not set a primary key before saving a newly created table, MS Access will ask
if you want it to create a primary key for you. If you answer Yes, Microsoft Access will create an
AutoNumber primary key.
If you have a field that contains unique values such as ID numbers or part numbers, you can designate
that field as the primary key. If the field you select as primary key does have duplicate or Null values,
Microsoft Access will not set the primary key. You can run a Find Duplicate query to determine
which records contain duplicate data. If you cannot really eliminate duplicate entries by editing your
data, you can either add an AutoNumber field and set it as the primary key or define a multiple-field
primary key.
In situations where you cannot guarantee the uniqueness of any single field, you may be able to
designate two or more fields as the primary key. The most common situation where this arises is in
the table used to relate two other tables in a many-to-many relationship. The Order detail table in the
Customer database is such a table, relating the Orders and Customers tables. Its primary key can
consist of two fields: Customer number and OrderID. The Customer details table can list many
customers and many orders, but each customer can only be listed once per order, so combining the
Customer # and OrderID fields produces an appropriate primary key.
The table Design View and the Datasheet View look similar to a spreadsheet, whereby columns and
rows can be increased or decreased. Row(s) and Column(s) can also be inserted. Note that a field
cannot be deleted unless the row is deleted.
This area of the table is mainly used for entering data (records) directly into the table. MS Access
tables are organized into a series of rows and columns. The columns are called fields (e.g. Student
Number) and the rows are called records (e.g. data within a line). It is displayed in a tabular form,
and data is entered similar to entering data in spreadsheet program. Working in this area is easier
because data can be formatted, found and replaced, sorted, modified etc.
Datasheet View
a. Launch MS Access
b. Select Blank Database
c. Type a name
d. Click on Create
e. Click on view
f. Make option
3.16 Query
It is a way to bring information from multiple tables or queries in a query linking. They are objects
just as a table is an object. Thus, you can have multiple queries related to one table. E.g. you can have
one query to display data on a specific criterion then save and second query on different criteria with
another name by using Save As command. The merit is that once you create query, you can use it
repeatedly with one or more tables in a database.
There are different types but the most common ones users used are Select and Update Query. A select
query simply selects information from the table while an update query updates some of the fields in
the table by replacing values.
field column, open the field list box by checking the arrow pointing downwards and select the require
field.
Table Row: Show the name of the table from which the field has been selected automatically.
Sort Row: Where the user can determine the arrangement of the data by using a particular record as
the sort key.
Show Row: Determines whether the contents of a field in the field row should actually appear in
the query when runs. Tick the show option for the field to be listed when applicable.
Criteria Row: Enable a user to specify the condition that should be satisfied before showing a record
mane query result. Conditional operators are only used to specify entries in setting; you must enclose
the criterion with double quotation marks when comparing text. Double quotation marks are not
included when comparing number data.
Operators Description
= Equation
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
* Multiplication
+ Addition
/ Division
- Subtraction
Within the criteria, text as well as other data is placed in double quotation marks excluding numbers
and currency.
The Run command is used to execute the criteria that the user has made. If a match is found for the
stated criteria, the output will be given. You can also use the datasheet view to see the output.
Process
NB: The output can be saved after each setting with Save As command with different name.
3.16.5 Ways to bring together data from Multiple Tables or Queries in a Query
The power of queries lies in being able to bring together or perform an action on data from more than
one table or query. E.g. you might want to view a customer’s information with the orders he has
placed. To see this information, you need data from the Customers and Orders tables.
When you add more than one table or query to a query, you need to make sure their field lists are
joined to each other with a join line so that Microsoft Access will know how to connect the
information.
If tables in a query are not joined to one another, either directly or indirectly, Microsoft Access will
not know which records are associated with which table, so it will display every combination of
records (i.e. a “cross-product” or “Cartesian product”) between the two tables. Therefore, if each table
had 10 records in it, the query’s result will contain 100 records (10X10). It also means the query
might take a long time to run and ultimately might produce less meaningful results.
If you previously created relationships between tables in the Relationships window, Microsoft Access
automatically displays join lines when you add related tables in query Design View. If referential
integrity is enforced, Microsoft Access also displays a “1” above the join line to show which table is
on the “one” side of a one-to-many relationship and an infinity symbol to show which table is on the
“many” side.
Even if you have not created relationships, Microsoft Access automatically creates joins if you add
two tables to a query and the tables each has a field with the same or compatible data type and if one
of the join fields is a primary key. The “one” and “many” symbols are not displayed in this case,
because referential integrity is not enforced.
Sometimes the tables you add to the query do not include any fields that can be joined. In this
situation, you have to add one or more extra tables or queries to serve solely as a bridge between the
tables whose data you want to use. E.g. if you add a Customers and Order Details table to a query,
they will not have a join line between them because they do not have any fields that can be joined.
But the Orders table is related to both tables, so you can include the Orders table in your query to
provide a connection between the other two.
Once tables and queries are joined, and you‟ve added fields from either tables or queries to the design
grid in query Design View, the default join tells the query to check for matching values in the join
fields. This is called an inner join in database terminology. When it finds matches, it combines those
two records and displays them as one record in the query‟s results. If one table or query does not
have a matching record in the other table or query, neither record appears in the query’s results.
This process is used in all the different items under object or working windows
Open on View under Home Menu and make option
Datasheet View
The view displays the information in a tabular form similar to a normal worksheet. Worksheet features
can be applied to this view, e.g. sorting, filtering, printing, text formatting and many more. In this
view, you can see the total number of records. You also can easily modify and append records.
3.17 Sorting
Sorting simply means rearranging data in a particular order either ascending or descending
(chronological) order.
3.17.1 How to Sort a Data
3.17.2 Filter
Filter is the quick and easy way to find and work with an entity of a data in a list to suit you or to
display one record at a time. A filtered list displays only the rows that meet your criteria specified for
a column(s).
Filter does not rearrange the data; it uses the line(s) as a key. Once filtered for just one record, it can
be printed.
A window that displays the SQL (structural Query Language) statement for the current query or is
used to create an SQL-specific query (union, pass-through, or data definition). When you create a
query in Design view, Microsoft Access constructs the SQL equivalent in SQL view.
You can recover your records from one database into another if the original database is
malfunctioning. The SQL enables you to append records from one database to another with the same
table structure in both databases that is the malfunction database and the new functional database.
An example is the relationship between a Customer table and an Order table, in which each customer
can have many orders, but each order is related to only one customer.
3.19.1 Relationship
An association established between common fields (columns) in two tables. A relationship can be
one-to-one, one-t-many, or many-to-many.
There are many types of calculations you can perform in a query. For example, you can calculate the
sum of average of the values in one field; multiply the values in two fields, to calculate the date three
months from the current date.
When you display the results of a calculation in a field, the results are not actually stored in the
underlying table. Instead, Microsoft Access reruns the calculation each time you run the query so that
the results are always based on the most current data in the database. Therefore, you cannot manually
update the calculated result.
The Query tab is mainly used for making a decision such as sorting or setting criteria. I.e. allow Users
to ask questions about the data in the Access table. In query design view is the area where users can
give an example of the type of information he/she desires and retrieving the data quickly. Working
with Query, you simply select information from the table.
g. Type the second field and enclose it with a parenthesis [Unit Cost]
h. Close bracket
i. Run for result
NB: You can use percentages for your calculation but here the percentage sign (%) is not accepted
unless you convent it into decimals. E.g. 7% = .07
3.22 Forms
Are objects that allow the User to determine how record and fields would be appeared on the screen?
It is common to use forms to develop a customized screen for entering data into a table. Instead of
entering data into a table where a multiple record would appear, a Form is not like that, it forms single
record entry. The form design view displays a grid on which you arrange text, fields, diagrams and
graphics.
A Form allows you to customize window to display to make entry and editing data easier. The design
of a form should be presentable, functional and attractive. It should contain the information needed
by those who use the form to enter data. The form also should help with data entry. Of these reasons,
the most critical element in using a Form is planning. You should however note that the table or query
is what is used for designing a Form.
3.22.2 Creating a Form
The only way of choosing field is to select the field from the field list box, click and drag to a desirable
place within the Form design grid before releasing your hand. Once the field has been inserted, it can
be copied, deleted, repositioned, resized, filled etc. heading, pictures and label can be appended to
make it more appealing.
3.23 Reports
One of the strengths of Access is its ability to produce a wide range of reports. In MS-Access, a
report allows you to present data in a meaningful, attractive, and professional way
The reports are objects used to arrange set of data in a table. Microsoft Access provides a standard
report as well as opportunities to develop customize report. You can edit a design of a report by
adding title, numbers and page footers etc.
The only way of choosing fields is to select the field from the field list box, click and drag to a
desirable place within the Form design grid before releasing your hand. Once the field has been
inserted, it can be copied, deleted, repositioned, resized, filled etc. Heading footers, pictures and label
can be appended to make it more appealing.
b. Make option from fill colours, fonts, fill effect, etc from the formatting bar
The report design view is the platform that allows a user to modify existing reports. Once the field
has been inserted, it can be removed, formatted, moved etc. However, you can also use a variety of
tools within the toolbox window to enhance the appearance and usefulness of the report. One of the
most powerful tools in a report involves the calculated controls. This control allows you to use
expressions and functions. To modify any field, the user ought to display its property dialog box for
easy customization and formatting.
Since you have the basic understanding of the process for generating and using forms, it is time to
consider a form/report wizard. It is usually easier to generate a form/report with the wizard than to
create from scratch. Using the wizard is easier. All that you need is to answer questions and provide
the information needed.
3.25 Data Access Pages: What They are and how They Work
A data access page is a special type of Web page designed for viewing and working with data from
an Internet or Intranet. Data is stored in a Microsoft Access database or a Microsoft SQL Server
database. The data access page may also include data from other sources, such as Microsoft Excel.