LO1 - Creating Database Objects
LO1 - Creating Database Objects
Level II
LEARNING GUIDE # 1
Unit of Competence: Operate Database Application
Module Title: Operating Database Application
LG Code: ICT ITS2 LO1 01
TTLM Code: ICT ITS2 TTLM 0614
This learning guide was 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
1. Read the specific objectives of this Learning Guide.
2. Read the information written in the “Information Sheets 1- 2”.
3. Accomplish the “Self-check” in pages7.
4. If you earned a satisfactory evaluation proceed to “Information Sheet 2”. However, if your rating is
unsatisfactory, see your teacher for further instructions or go back to Learning Activity # 1.
5. Submit your accomplished Self-check. This will form part of your training portfolio.
6. Read the information written in the “Information Sheet 2”.
7. Accomplish the “Self-check” in page 19.
8. If you earned a satisfactory evaluation proceed to “Operation Sheet” in page 20. However, if your
rating is unsatisfactory, see your teacher for further instructions or go back to Learning Activity #2 .
9. Read the “Operation Sheet” and try to understand the procedures discussed.
10. Do the “LAP test” in page 33 (if you are ready) and show your output to your teacher. 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 Learning Guide 2.
A database can best be described as a way of storing large amounts of information. The data
can be retrieved and we can even ask questions of the data and get answers. For example:You may
want to know how many Students enrolled in every occupational level.
Ms Access is a database management tool that enables one to store relevant data.
This also has the capabilities to retrieve, sort, summarize and reportresultsimmediately
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
singledatabase file. Within the file, one can use the different objects:
Tables - A table is a collection of data about a specific topic, such as products or suppliers.
Using a separate table for each topic means that you store that data only once. This results in
a more efficient database and fewer data-entry errors.
Queries - You use queries to view, change, and analyze data in different ways. You can also
use them as a source of records for forms, reports, and data access pages.
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
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
itappears.
Production data or Treatment information. Data should not be duplicated in multiple tables.
Microsoft Access provides three methods to create a database
Database Wizard (though easy, the wizard offers limited options to customize thedatabase)
Using a template (This method works best if one can find and use a template thatclosely
matches the specific requirements)
Creating a database directly (This is the most flexible method, but it requires one todefine
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:
Dataareraw 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 Gende Bday Address
r
MOE-0001 Cuevas Noel Pancho Male 11-05-1978 Aratkilo
(this is an information about a person named “Noel”)
Naming Convention
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.
3. Ms Access database file was saved with what extension name? (1 point)
7. What are the three things to consider in establishing a naming convention? (3 points)
1. database
2. a. Tables
b. Queries
c. Forms
d. Reports
eModules
f Macros
g. Page
3. .mdb
4. a. Database Wizard
b. Using a template
c. Creating a database directly
5. information
6. Table
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
Metadata – is a “data about data” or synonymously called table structure that defines
what type of data your data is?
(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: Richard23. 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 rowin a table represents a record, which is a collection of meaningful data.
Fieldnames
“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.
Text: allows for the storage of any kind of data, characters, digits and special
characters. It has a defect length of 50 characters with a maximum length of 255. It is
normally used to store data such as names, addresses, or any number not used in
calculations, like telephone numbers or zip codes.
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.
In Access2003 it is possible to arrange or group in a Memo field, but Access only uses
the first 255 characters when it arranges or groups in 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.
TTLM Development Manual Date: 08-2006 Page 9 of 39
Author: BTVET
Currency: For monetary values and numerical data used in mathematical calculations
in which the data involved contains between one and four decimals. The accuracy is up
to 15 digits to the left of the decimal separator and up to 4 digits to the right of the same.
Access recommends the use of Currency type to avoid the rounding off of numbers in
calculus. A Currency field has an accuracy of up to 15 digits to the left of the decimal
separator and 4 digits to the right. A Currency field occupies 8 bytes of space on disc.
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 64characters long. They
can include any combination of letters, numbers, spaces, andspecial characters except a period (.),
an exclamation point (!), an accent grave (`), andbrackets ([ ]). 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 agood idea. If you don't define a primary key, Microsoft Access asks if you want
Accessto create one for you when you save the table)
Forms
Queries
A query is a derived item in the database meant to answer specific questions that relate to
theinformation in the database. It is the means to retrieve relevant information in one or more tables.
Queries are handy during data processing.
Reports
TTLM Development Manual Date: 08-2006 Page 11 of 39
Author: BTVET
Reports provide a means of organizing and summarizing data. Reports are often used
topresent an overview highlighting main points and trends. A report can be a simple list, a
statusreport or a monthly production report.
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
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:
You create VBA programming code by using the VBA Editor, which is described in the
following section.
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 windowarethe 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.
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.
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.
9. What do you call the editor where you will write your macro code? (1 points )
Answer Key:
1. table Structure
2. data
3. fieldname
4. record
5. primary key
6. a. Design View
b. by using a Wizard
7. a. Design View
b. by using a Wizard
c. SQL view
9. VB editor
Before you can create a database objects, you need to launch first the MS Access Software and then
create a blank database.
(2)click Blank
(1)click New icon database..
(3) Type a
File name (4) click Create
button
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
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.
Note: For the Data type please refer to the Information Sheet 2 – Creating database objects.
To insert new fields within the table, in design view, 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
nextto 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’.
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 Valueof 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
TTLM Development Manual Date: 08-2006 Page 23 of 39
Author: BTVET
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 Ruleallows 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 isthe 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 whenset 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 alphabetically
but would not allow you to enter the same value (you cannot enter an ID number that already
exist).
After that, press Ctrl+Son the keyboard toSave your table. It would ask you to enter a Table Name.
Replace Table1 with T_StudentsListthen click OK button.
Note: Same rule applies in naming a table. No spaces please. Make it one-word like T_StudentsList.
Navigation bar
To modify a record, you just go to the specific fields of the record and modify it.
Creating Forms
TTLM Development Manual Date: 08-2006 Page 25 of 39
Author: BTVET
There were 2 ways to create a form
1. Create form in design view
2. Create form by using wizard
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 fieldsfrom 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
the columnar then click next. Layout and then click next.
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
records to your table using the form. It would also allow you to delete records through the
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.
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
TTLM Development Manual Date: 08-2006 Page 29 of 39
Author: BTVET
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
TTLM Development Manual Date: 08-2006 Page 30 of 39
Author: BTVET
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
below the course field to create a small button
4. On the Control Button Wizard, choose Form
Operations then choose Close Formthen
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.
Creating Queries
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 abve. 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
Just click on the Reports, then double-click on Create report by using wizard. Follow the series of
steps below in creating an IT Students List:
Creating Macros
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 module, double-click the module file that you have just created. It would then
launch the report preview of R_ITStudentsList report as shown below.
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 messageabout your system. You can now close the Microsoft Visual
Basic Form.
Just click on the Pages, then double-click on Create data access page by using
Wizard.
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.
TTLM Development Manual Date: 08-2006 Page 37 of 39
Author: BTVET
Lap Test 1 Creating database objects
b. Createa Formby Using a Wizardfor the table above then save it as StudInfoForm.
Create also a navigation buttons in design view.
c. Create a Queryin Design View then save it as StudInfoQuery. In your query, add the
tableStudDB as your source table then on the Field NamechoosestudID, studLname,
studFname, studMname. Afterthat, close your query.
d. Createa Reportby using a wizard then save it as StudInfoReport. On your report will
display all the fields of the table StudInfoTablehave it displayed in Ascending order by
studLname.
e. Createa New Macro then save it as StudInfoMacro. On the Form name, choose
StudInfoTableand then on the Action, choose OpenForm. Save and close it.
f. Create a New Module then save it as StudInfoModule. Under the Option Compare
Database, type this code:(save it after the close)
Sub openStudInfoForm()
DoCmd.openform "StudInfoForm"
End Sub