Professional Documents
Culture Documents
Ethiopian TVET-System
INFORMATION TECHNOLOGY
SUPPORT SERVICE
Level I
LEARNING GUIDE # 1
Unit of Competence: Operate Database Application
Module Title : Operating Database Application
LG Code : ICT ITS2 M01 L01 01
TTLM Code : ICT ITS2 TTLM01 0511
This learning guide is developed to provide you the necessary information regarding the following content
coverage and topics –
This guide will also assist you to attain the learning outcome stated in the cover page.
Specifically, upon completion of this Learning Guide, you will be able to –
Learning Activities
Your teacher will evaluate your output either satisfactory or unsatisfactory. If unsatisfactory, your
teacher shall advice you on additional work. But if satisfactory you can proceed to the next topic.
Ms Access is a database management tool that enables one to store relevant data.
This also has the capabilities to retrieve, sort, summarize and report results
immediately and effectively. It can combine data from various files (tables)
through creating relationships, and can make data entry more efficient and
accurate through the use of forms.
Microsoft Access (MS Access) enables one to manage all important information from a
single database file. Within the file, one can use the different objects:
Forms - A form is a type of a database object that is primarily used to enter or display
data in a database. You can also use a form as a switchboard that opens other forms and
reports in the database, or as a custom dialog box that accepts user input and carries out
an action based on the input.
Reports - A report is an effective way to present your data in a printed format. Because
you have control over the size and appearance of everything on a report, you can display
the information the way you want to see it
Modules - A module is essentially a collection of declarations, statements, and
procedures stored together as one named unit to organize your Microsoft Visual Basic
code. Microsoft Access has two types of modules: standard modules and class modules.
Data access pages - A data access page is a special type of Web page designed for
viewing and working with data from the Internet or an intranet— data that 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.
In MS Access, data is stored once in one table, but can be viewed from multiple locations.
When the data is updated in a Table, Query or Form, it is automatically updated everywhere it
appears.
Database Wizard (though easy, the wizard offers limited options to customize the
database)
Using a template (This method works best if one can find and use a template that closely
matches the specific requirements)
Creating a database directly (This is the most flexible method, but it requires one
to define each database element separately).
Basic Database Concept: In studying MS Access, it is but necessary to understand some basic
elements of a database before proceeding to it.
Database Elements:
Data are raw facts. It tells the truth about something; a person, a place, an object, etc.
Example:
Information is a collection of data (raw facts) which is contained in 1 file (table in Access)
Example:
IDNumber LName FName Mname Gender Bday Address
MOE-0001 Cuevas Noel Pancho Male 11-05-1978 Aratkilo
(this is an information about a person named “Noel”)
Naming Convention
Is manner of naming files and variables. Having a poor naming convention can only add
confusion, so it's important that you start with a good scheme, and think about what the scheme
will mean to you. Here are the three things to consider in establishing a naming convention:
1. Does my convention make sense to me?
Is must be simple and understandable to you.
2. Will my convention make sense to other people?
Time will come that other people will look into your database program, so they
must able to understand it.
3. Can I be consistent in implementing and enforcing my convention?
All throughout my database work, your naming convention must not change.
General
Here are some basic simple rules when it comes to the name of any object in a database
(including the name of the database itself):
Do not use spaces in object names. It might seem tempting and cute to have a view
named "Sales By Quarter," but this is a nightmare to deal with programmatically. Instead
write it as “SalesByQuarter” or “SalesByQtr” or “QtrlySales”
Avoid using reserved words. This is easier said than done, as there is a very large list
of current and future reserved words to check against. Example: do not name your file as
“Date” because “Date” is a reserve word in Ms Access.
Do not use dashes in database names. Dash “-“ was often recognized by a computer
as an operator (subtraction), so instead of naming your object as “Quarterly-Sales”
better name it as QuarterlySales” or better use underscore instead of a dash
“Quarterly_Sales”.
Start object names with a letter. I see table named "2005_Sales" and columns and
columns named "1", "2," "3," and so on (to represent months). Ms Access might treat it
as a number and not as a filename.
Keep names short but meaningful. This is self-explanatory and fairly logical, "SlQ" is
too short. “SalesFiguresForCompanyByFiscalQuarter" is just silly.
Use sensible case. There is little worse than going through a database schema where
all the table names are in ALL CAPS. It’s like Ms Access is yelling at you! Likewise, trying
to read a procedure name like "getallarticlestatisticsbyweek" could drive some people to
drink. I like camel-/Pascal-casing or using underscores, leaning toward the former in most
cases: GetArticleStatsByWeek or getArticleStats_ByWeek.
Avoid Hungarian notation. The name of the object should make it pretty obvious what
type of data it contains, and if for some reason it does not, then there is always the
metadata tables and/or the documentation you should have written when designing the
system. Using datatype-style prefixes for columns like IContactID (integer) and VEmail
(varchar) not only make the column names harder to read, they also make them less
flexible.
Learning Guide Page 5 of 44
1st Revision
Major General Mulugeta Buli Technical College
Training, Teaching and Learning Materials Development
Name:____________________ Date:_________________
Instruction: Answer all the questions listed below, if you have some clarifications- feel free to ask your teacher.
Please ask your trainer for the questionnaire for this Self-Check.
Creating DB Tables
Recently, we define it as a file but technically, it was defined as a container or a
worksheet-like container where the collection of data has been stored.
Before we proceed to creating your first table, we need to know first the basic
components of a table:
o Meta Data – Database Structure
o Field – Column – Data
o Fieldname
o Record - Row - Information
(2) Supposed that “21” is the Age of Noel, then we will define Age as a
number, specifically an Integer so it will only accept a value which is an integer.
Which only means to say that you cannot enter a number value in the Firstname
field, likewise you cannot enter a text value to the Age field. In that case, entering a
number value to a Firstname field would treat it as text. Ex: Noel23. And cannot be
used for computation.
Field – Every column in a table represents a field by which data has been stored.
Field name – This refers to the name of every field.
Records – Every row in a table represents a record, which is a collection of meaningful
data.
Field names
“MOE-0001” is the data for IDNumber field. And IDNumber is a fieldname for that data.
Data Types
When creating a table, one will need to specify what kinds of data are to be stored in this
field.
Memo: is used for texts of more than 255 characters such as comments or
explanations. It has a maximum length of 65.536 characters. Access recommends
that to store formatted text or large documents, rather to create an OLE Object
field than a Memo field.
Number: for numerical data used in mathematical calculations. Within the number
type we are able to specify the size property of the field. The types Byte, Integer
and Long Integer allow the storage of numbers without decimals; the types Single,
Double and Decimal allow decimals; the type Replication ID is used for
autonumerical codes in replication databases.
Date/Time: for the introduction of date and time from the year 100 to 9999.
Yes/No: Yes and No values, and fields that contain one of two values (Yes/No,
True/False or Activated/Deactivated).
Hyperlink: text or a combination of text and numbers stored as text and used as a
hyperlink address. A Hiperlink is a text or graphic that you click to go to a file, a
location in a file, a web page on the Internet, or a web page on an intranet.
Each field in the design view of a table corresponds to a column in the datasheet view of a
table.
Entering unique names of the columns of the table in the “field name” column of the
design view. Names of fields and objects in Microsoft Access can be up to 64 characters long.
They can include any combination of letters, numbers, spaces, and special characters except a
period (.), an exclamation point (!), an accent grave (`), and brackets ([ ]). They also can't
begin with leading spaces
Primary Key is the unique identification of one record. It will not allow a duplication of
the Primary Key thus make it unique. Define a Primary Key field (You don't have to define a
primary key, but it's usually a good idea. If you don't define a primary key, Microsoft Access
asks if you want Access to create one for you when you save the table)
Name:____________________ Date:_________________
Instruction: Answer all the questions listed below, if you have some clarifications- feel free to ask your teacher.
Please ask your trainer for the questionnaire for this Self-Check.
Example of a form
Forms
A form is a type of a database object that is primarily used to enter or display data in a
database. Most forms are bound to one or more tables and queries in the database. A form's
record source refers to the fields in the underlying tables and queries.
Control Toolbox
Queries
A query is a derived item in the database meant to answer specific questions that relate
to the information in the database. It is the means to retrieve relevant information in one or
more tables. Queries are handy during data processing.
Reports
Reports provide a means of organizing and summarizing data. Reports are often used to
present an overview highlighting main points and trends. A report can be a simple list, a status
report or a monthly production report.
(Example of a report)
Name:____________________ Date:_________________
Instruction: Answer all the questions listed below, if you have some clarifications- feel free to ask your teacher.
Please ask your trainer for the questionnaire for this Self-Check.
Macros
Macros in Access can be thought of as a simplified programming language which you can
use to add functionality to your database.
For example, you can attach a macro to a command button on a form so that the macro
runs whenever the button is clicked. Macros contain actions that perform tasks, such as opening
a report, running a query, or closing the database. Most database operations that you do
manually can be automated by using macros, so they can be great time-saving devices.
A macro is essentially a list of actions that you apply to objects to respond to events. Each
action carries out one task. You create your actions in the order you want them to execute. In
addition, you specify the arguments of the actions, giving the program additional information as
needed.
You can set conditions for each action in a macro to determine whether it runs or not. Run
a macro by applying it to the event property of an object. Once the specified event occurs the
macro will run by running the all the specified actions. Actions that have conditions applied to
them may or may not run depending on whether or not they passed the conditional tests.
Once you've created your macros you'll see them listed in the Macros tab in the Database
window. This way you can attach any macro to any event property in your database.
Modules
Modules, like macros, are objects you can use to add functionality to your database.
Whereas you create macros in Access by choosing from a list of macro actions, you write
modules in the Visual Basic for Applications (VBA) programming language. A module is a
collection of declarations, statements, and procedures that are stored together as a unit. A
module can be either a class module or a standard module. Class modules are attached to forms
or reports, and usually contain procedures that are specific to the form or report they're
attached to. Standard modules contain general procedures that aren't associated with any other
object. Standard modules are listed under Modules in the Navigation Pane, whereas class
modules are not.
Now that you know how to put together a program, you are ready to give it a try. To
create a VBA procedure, you follow many of the same steps you follow when you created
macros. The general steps in VBA programming are as follows:
1. Identify the task you want to accomplish
2. Plan the steps needed to accomplish that task
3. Create the programming code necessary to implement the steps
4. Test the program
5. Refine the program
6. Repeat steps 4 and 5 until the program works correctly
You create VBA programming code by using the VBA Editor, which is described in the
following section.
Module window
Properties window
Immediate window
In the upper left corner is what the editor refers to as the Project window. This is where
you can see the different elements of your project and any modules that have been defined in
the workbook.
Just below the Project window is the Properties window. Here you can specify different
attributes of whatever you have selected in the Project window. For most simple development
needs, you will never do much with the Properties window.
To the right of the Properties window, and at the very bottom of the screen, is the
immediate window. This is where you can either test parts of your procedures during
development or you can find the immediate results of various commands. The Immediate
window comes in very handy during testing and debugging, when they are necessary.
Note: If a window is not displayed within the VBA Editor, you can display it by choosing one
of the options from the View menu. For instance, if you want to display the Project window,
choose Project Explorer from the View menu.
The Module window, which is the largest window on the screen, is where you do your
programming. At the top of the Module window are the two drop-down lists. The one on the left
is called the Object box. The one on the right is the Procedure box. You use the Object box to
select which object you want to work with. When you first create a module, the object is set to
the word General, meaning you are working on a general module, not on one associated with a
particular object in a form or report.
The Procedure box is where you indicate the name of the procedure on which you want
to work. If you choose or specify a different procedure in this box, the information Access shows
in the Module window changes to reflect the VBA statements you have assigned to that
procedure.
The top level of a module is the Declarations section; It begins with the procedure
name you indicate in the Procedure box when you first create a module. Take a look at the
Module window (Figure 20-1). It contains the programming code already defined for the
declarations section. In this instance, there is only one line of code defined--a statement that
indicates the database's default sort order.
To enter programming statements into a procedure, you type them in the Module window.
As you enter information, Access checks to make sure it can understand what you type. In other
words, Access checks the syntax of what you enter. You use the correct syntax when you follow
the VBA rules of grammar.
You can cut, copy, and paste sections of code using standard Windows mouse or keyboard
techniques. You can perform these operations either in the same procedure or between different
procedures.
Using a data access page is similar to using a form: You can view, enter, edit, and delete
data in a database. However, you can also use a page outside a Microsoft Access database, so
users can update or view data over the Internet or an intranet.
The body - The body is the basic design surface of a data access page. On a page
that supports data entry, you can use it to display informational text, controls
bound to data, and sections.
Sections - You use sections to display text, data from a database, and toolbars.
Two types of sections are typically used on pages that support data entry: group
header and record navigation sections. A page can also have footer and caption sections.
Group header and footer Used to display data and calculate values.
Record navigation Used to display the record navigation control for the group
level. A record navigation section for a group appears after the group header
section. You can't place bound controls in a record navigation section.
Caption Used to display captions for text boxes and other controls. It appears
immediately before the group header. You can't place bound controls in a caption
section.
Each group level in a data access page has a record source. The name of the record
source is displayed on the section bar for each section used for a group level.
Interactive reporting. This type of data access page is often used to consolidate and
group information that is stored in the database, and then publish summaries of the data.
For example, a page might publish the sales performance for each region in which you do
business. Using expand indicators, you can go from a general summary of the
information, such as a list of all the regions and their combined sales total, to specific
details on individual sales within each region. The data access page might provide toolbar
buttons for sorting and filtering the data, as well as for adding, editing, and deleting the
data in some or all group levels.
Data analysis. This type of data access page may include a PivotTable list, similar to a
Microsoft Excel PivotTable report, that lets you reorganize the data to analyze it in
different ways. The page might contain a chart that you can use to analyze trends, detect
patterns, and compare data in your database. Or it might contain a spreadsheet, in which
you can enter and edit data and use formulas to calculate as you do in Excel.
A data access page is connected directly to a database. When users display the data
access page in Internet Explorer, they are viewing their own copy of the page. That means any
filtering, sorting, and other changes they make to the way the data is displayed— including
changes they make within a PivotTable list or spreadsheet— affect only their copy of the data
access page. However, changes that they make to the data itself— such as modifying values,
and adding or deleting data— are stored in the underlying database, and therefore are available
to everyone viewing the data access page.
Note: To view and work with the data access page on the Internet or an intranet, users
need Microsoft Internet Explorer 5.01 with Service Pack 2 (SP2) or later.
You can also work with a data access page in Page view in Access. Data access pages can
supplement the forms and reports that you use in your database application. When deciding
whether to design a data access page, form, or report, consider the tasks that you want to
perform.
Name:____________________ Date:_________________
Instruction: Answer all the questions listed below, if you have some clarifications- feel free to ask your teacher.
Please ask your trainer for the questionnaire for this Self-Check.
Before you can create a database objects, you need to launch first the MS Access Software and
then create a blank database.
To launch MS Access 2003
Click on the Start button> All Programs > Microsoft Office> Microsoft Access 2003
(2)click Blank
(1)click New icon database..
(3) Type a
File name (4) click Create
button
Note: your file name must not have a space. It must be 1 word. MyfirstDB is a valid
file name, My first DB is invalid. You can define your own file name but for this purpose
let’s just use MyFirstDB. You may or may not include .mdb as an extension name. It
would by default add .mdb to your filename, thus, make it MyFirstDB.mdb.
Creating a Table
After creating a Blank database, you are now ready to create your first object, let’s start
with the Table.
Creating a table would start by creating a table structure which would define every field in
a table. Let us create a table T_StudentsList and let’s define the following fields as follows:
Field Name Data Type Description (describes each field – optional)
StudentID Text ID number of students
Lastname Text Last name of students
Firstname Text First name of students
Middlename Text Middle name of students
Birthday Date Birth day of students
Gender Text Gender of students
Course Text Course of students
You are now ready to create your first database object, the table.
Double-click Create table in design view then a blank table structure template will
appear.
Enter value for Field Name, Data Type and Description as shown in the figure below.
To make a pre-defined Course list, click the lookup tab properties then choose Combo Box on
the Display Control. On the Source List, choose Value List the start typing “Management” ; “IT”;
“Computer Science”; “Accountancy”; Computer Engineering.
To put primary key to a field, click on the field then click the key on the toolbar
above and the key will appear on the left side of the key. When you set one field as primary
key, you couldn’t input the same value for that field.
To insert new fields within the table, in design view, right-click in the row below where
you want to add the field, and then click Insert Rows on the toolbar.
To add the field to the end of the table, click in the first blank row.
To change from one view to another, make a selection on the View menu or click the
arrow next to the View button and choose from the list that appears.
To view, enter, and change data easily and directly in a table, create a ‘form’.
In the lower portion of the window Field properties, please refer below:
Field size defines the number of characters you’re a text field can contain.
Format is normally use for a field that has a data type of Number or Date. Click on it to
define custom settings you want.
Input Mask was good in setting-up initial constant values. Setting an input mask for ID
number field to “MOE-999999” would mean that when you enter a value for that field it
would initially give you a value of MOE-_ _ _ _ _ _ . “999999” allows you to enter any 6-
digit numbers. So, you don’t need to type MOE- because it would automatically appear.
You just need to add a 6-digit value to it to complete its value. For example: typing
“000123” gives you “MOE-000123”.
Caption defines the label of a field. Writing “Last name” on a Caption of the Lname.
See the Caption on the table input view later.
Default Value gives you an initial value. If you are expecting more Male students, you
better put “Male” on the Default Value of your Gender field so that when you input a
record, it would automatically appear a Male on your Gender field so you don’t need to
type it anymore. In case of a Female gender, you can alter it anyway. You would save
time for all Male inputs since you don’t need to type it anymore.
Validation Rule allows you to filter the values you just want to input for a particular
field. Setting a Gender field Validation Rule to “Male” or “Female” would mean that it
would only accept a Male and Female value for Gender field. Typing F or M to it would give
you an error-message.
Validation Text is the counterpart of Validation Rule. Instead of displaying a computer
generated error-message when you input a wrong value to a field, you can set your own
error-message. You just type the text you want. Example: “Wrong Input!”
Required field when set to Yes would not allow you to skip a certain field leaving it
blank.
Indexed when set to OK (Duplicates OK) would sort out a field alphabetically and it
would accept duplicate values, when set to OK (No Duplicate) would sort out a filed
After that, press Ctrl+S on the keyboard to Save your table. It would ask you to enter a
Table Name. Replace Table1 with T_StudentsList then click OK button.
Note: Same rule applies in naming a table. No spaces please. Make it one-word like
T_StudentsList.
To input data, double-click the T_StudentsList table and you’re now ready to input
records to it.
Navigation bar
To modify a record, you just go to the specific fields of the record and modify it.
Let us try to create a form by using wizard. On the left pane, click on the Forms tab
then double click the Create form by using wizard.
Choose all fields from the table T_StudentsList by clicking on the double greater than
sign.
The single greater than ( < ) allows you to choose 1 selected field from the Available
Fields. To do the opposite (to deselect the field/s), click the less than or double less than sign.
After that, choose layout from the list. Choose also the form style you want.
For this exercise, choose the default layout, Again for this exercise, you choose Standard
Just like the table, when you run the form in form view, it has its navigation button below
it that would allow you to navigate from one record to another and would also allow you to add
Record
Selector
Navigation buttons
The next thing that you will need to do is to create your own customized navigation
buttons. Let’s now go back to your form’s design view.
Now, expand the form a bit by pointing the cursor on the bottom rightmost corner then
dragging while holding the left mouse click diagonally down as shown on the figure on the right.
Next, select all the fields by dragging the mouse through the form while holding the left click
making sure it would go over the entire fields as shown in the figure on the left
After selecting all fields, drag it all down to center into the form. Do it by dragging while
holding the left click of the mouse.
Add a label by clicking the “Aa” on the Toolbox then dragging it on the top part of the
form just up a bit to StudentsID field as shown on the left.
Type Students’ Database on it then make the label a bit bigger by clicking your cursor
anywhere in the form then clicking back on the label to select it again. Afterwards you can now
change the font and its size on the toolbar above,
1. Wizard
2.button
3.
You have just created your first navigation button that would allow you to go to the first
record when you run it in form view.
Let’s now create the rest of the navigation buttons as shown below.
1. Go to the first record
2. Go to the previous record
3. Exit
1 2 3 4 5 4. Go to the next Record
5. Go to the Last Record
3. Exit button
To do that, do the following Button Wizards Steps:
1. Click on the wizard on the toolbox
2. Click the button on the toolbox
3. Drag the cursor while holding the left click
Learning Guide Page 35 of 44
1st Revision
Major General Mulugeta Buli Technical College
Training, Teaching and Learning Materials Development
below the course field to create a small button
4. On the Control Button Wizard, choose Form
Operations then choose Close Form then
click next.
5. Click the default button icon picture then
click next.
6. Name your button as B_Exit then click
Finish.
You are now finished creating your navigation buttons. Close it then save. To view it,
double-click the F_StudentsList form. When it opens, try navigating from one record to another.
Click all the buttons you have made and see how it works.
Just click on the Queries, then double-click on Create query in design view. In the
Show Table pop-up, add the T_StudentsList table. A table will show-up on top part of the
query. Double click one by one all the fields on the table so it would appear on the table-like
sheet below. All the fields that you have selected would appear on the query view with the
corresponding records depends on your criteria.
Try putting “IT” on the course criteria as shown above. Close and save your query as
Q_ITStudentsList. Double-click on the Q_ITStudentsList to view the results of your query. It
would then show the list of all records whose course is “IT” as shown below.
Creating Reports
Save it then close it. To preview your report, double click on the report file
R_ITStudentsList.
Note: to run the report, you would need to create a button in a form embedded with macro
code or VBA code that once click, it would execute opening or printing of a report.
Let’s try to create a Macro that will open that will open the report that you have just
created. Click now on the Macros, then double-click on New. Choose OpenReport in the Action
column, then on the Report Name property below choose the report that you have just
created(R_ITStudentsList). On the view property, choose print preview. Press Ctrl+S to save.
Save your module as M_ITStudentsList_ReportOpen then close it.
To test your macro, double-click the macro file that you have just created. It would then
launch the report preview of R_ITStudentsList report as shown below.
You have now successfully created a macro. It’s so simple that you can play around with
it.
Creating Modules
Press Ctrl+S to save then save it as Md_About. You have just created a Module with a
function that will display the message about your system. You can now close the Microsoft
Visual Basic Form.
To perform the modules, you need to call it in your form Event Procedure to execute or
embed to a button by using a wizard. (see Form Event Procedure links to module codes in the
succeeding learning outcome).
To view the data access page, Click on Pages then double-click the data access page file
that you have just created.
Try to explore more the data access pages.
Instructions: You are required to perform the following individually with the presence of your
teacher.
Please ask your trainer for the instructions for this lap test.