SEHH1007 Tutorial - Microsoft Access 2016 (Lab 1)
SEHH1007 Tutorial - Microsoft Access 2016 (Lab 1)
What is Access?
Access is a DBMS software produced by MicrosoftTM. It operates under the
Windows operating system environment, allowing you to create and process data in
a database. Its data hierarchy is arranged as Files Tables Fields Records
Fields
1
Access uses similar terminology as most database systems do,
Access allows you to create a database and tables, design a data entry form, and
generate reports or graphs from the data. A key is a field that enables you to identify
or search for a record in a table. For example, your student ID is a key in the student
record table.
Creating a Database
2
Opening a Database
• Choose Open Other Files in the screen previously shown.
• Select the appropriate drive or browse the appropriate folder for the file you wish
to open.
• Select the desired database file and its file name will appear in the File name box.
• Press the Open button.
Creating Tables
A database may consist of many tables. You can create your own table which is
specially designed for your database. Once you create a database file successfully,
you will see the following screen. By default, Access will prompt you to create a
table by means of datasheet view. Table1 is a temporary name of the table you are
about to make.
3
Create table under All Access Objects
On the left of the screen shown previously,
• In the All Access Objects frame, click Table1 once under Tables.
(Note: if Table1 is not found, go to the Create Tab at the top, and click Table to
create a new one. More details can be found in the Create table in Create tab
section)
• Click Home-View group, and then choose Design View as shown below.
• At the Primary Key field, enter appropriate Field Name, Data Type, and
Description.
• Enter appropriate Field Name, Data Type, and Description for each other field, if
any.
• Click Save button in Quick Access Toolbar to save it.
4
Quick Access Toolbar
Save button
• Enter appropriate Filed Name, Data Type, and Description for each field to store,
if any.
• Put Primary Key to an appropriate field.
• Click Save button in Quick Access Toolbar to save it.
• Enter appropriate Table Name.
• Click OK button.
A Table Design window is displayed which allows you to modify or add fields in your
new table. Click Save button in Quick Access Toolbar to save your work. When
finished, you may close it.
5
e.g. Highlight Table 1
Right-click, choose
Design View
Modifying a Field
• In the Table Design window, you can modify your fields. Each field has a name
and a data type, with optional description.
6
Date/Time To store date and/or time values 6/19/2007 10:21:23 AM
(different formats).
Currency To store monetary values, up to 15 $5.00
digits on the left side of the decimal
point and 4 digits to the right side;
displayed in forms and reports in the
currency format.
AutoNumber A number automatically incremented 321
(or randomly generated) by Access
whenever a new record is added to a
table; it is most often used as a primary
key, maintained within Access and
cannot be changed by user.
Yes/No A data type when one of two possible Yes
answers is needed, such as yes/no,
true/false or On/Off. There are some
restrictions imposed on this data type,
so use it carefully.
Additional settings for each field can be made at the bottom, Field Properties.
Access allows you to define the following various properties for a field:
7
Field names can be in any string, but it is a good design to have spaces left out in
the fields for readability.
• The default data type is Short Text. Use the drop-down box to select other types.
Select the appropriate field size for a text type in Field Properties.
• Define a field to be a primary key by clicking that field and then hitting the
primary key button at the Tools group in the Design tab. There can only be
one primary key per table.
• When you have done, click Save button in the Quick Access Toolbar to save it.
• Make sure that there is a primary key before a table can be saved.
Inserting a Field
• Position the cursor to the field where you want to insert another field.
• Click the mouse’s right button, select Insert Rows button.
• Add the relevant information.
Deleting a Field
• Highlight the field you want to delete (click on the leftmost box of the field).
• Click the mouse’s right button, select Delete Rows button.
8
Access Exercise 1
1. Create a new database called yourname.accdb. If your name is Chan Tai Man,
then save the new database as ChanTaiMan.accdb.
2. Enter the following fields and descriptions to the table using Table Design in
Create tab.
Name Type Description Field Size
EmployeeID AutoNumber Employee ID number Long Integer
FirstName Short Text First name of employee 50
LastName Short Text Last name of employee 50
Married Yes/No Married Y/N Yes/No (format)
Birthday Date/Time Birthday (dd-mmm-yy) Medium date (format)
Address1 Short Text Address line 1 35
Address2 Short Text Address line 2 35
Address3 Long Text Address line 3
District Short Text District 15
Region Short Text Region 15
Performance Number Score (0 – 255) Byte
Position Short Text Employee position 2
Salary Currency Monthly salary Standard (format)
4. Open Employee2 in Design View. Insert the following field before Married:
Name Type Field Size Description
Gender Short Text 1 Gender F/M
5. Delete Address3.
9
Adding Records Using Datasheet View
Adding Records
• At the All Access Objects in the Navigation Pane on the left, select (highlight)
the name of the table you want to add records.
• Double-click the mouse’s left button.
• The Datasheet View window is displayed with the caption names of the fields as
the column headings. Each row represents a single record.
• If there are no records in the table, then you can just enter the data field by field.
• You can use <Tab> or <Enter> to move to the next field or record.
• AutoNumber field cannot be edited. Access will assign numbers automatically.
Don’t worry even if the numbers are not consecutively listed after the insertion
and/ or deletion of records.
10
Caution: You can only undo the change in one previous step. Make sure the
changes you make are correct. There is no alert box this time.
• At the All Access Objects in the Navigation Pane, select (highlight) the name of
the table you want to add records.
• Double-click the mouse’s left button.
• The Datasheet View window is displayed with the caption names of the fields as
the column headings. Each row represents a single record.
• Highlight the field you want to insert field (click on the top most box of the field).
• Click the mouse’s right button, select Insert Field from the menu. A field will be
added to the left.
• Highlight the field you want to rename (click on the top most box of the field).
• Click the mouse’s right button, select Rename Field from the menu. Type the
new field name.
• Highlight the field you want to delete (click on the top most box of the field).
• Click the mouse’s right button, select Delete Field from the menu.
Caution: You cannot undo the deletion of a column/field and the change of name.
You need to answer Yes on the alert message box to confirm a deletion.
11
• Choose Create tab, then choose Form Wizard in Forms group.
• A Form Wizard window will be displayed. In the Table/ Queries box, select the
table or query that you want to create a form for. On the left side, under
Available Fields, you will see a list of fields. You can select those fields that
need to be included in the input form.
• Select the fields using > button and click the Next button. Use the < button to
remove a field from the input form.
• Select the format of layout, say, Columnar or Tabular (for a small number of
fields) or Justified (for a large number of fields).
• Click the Next button.
• Give a name to the form and choose the Finish button.
• You will then see a form for you to enter the data.
2. Editing a Form
Whether you have created your form using Form Wizard or under Design View, you
can edit the form.
• At the All Access Objects in the Navigation Pane, select (highlight) the name of
the form you want to edit under Forms.
• Click the mouse’s right button, select Design View button from the menu.
• The Form Design View window is displayed.
• You may do the following editing if appropriate:
- Drag the fields and their captions on the form.
- Highlight items and hit <Del> to delete.
- Highlight text to change the caption/ label. Click the background to finish.
When you have finished, click Save button in Quick Access Toolbar to save it.
12
• Select Delete Record in Delete button in Records group in Home tab.
• When you have finished, click Save button in Quick Access Toolbar to save it.
Access Exercise 2
1. Open the database you created in Access Exercise 1 (yourname.accdb).
2. Open the Datasheet for Employee and insert the following records:
(Note: the table below shows information of records only. It does not show how
the Datasheet View in Access looks like.)
Name Record 1 Record 2 Record 3 Record 4
EmployeeID The value here is automatically assigned by MS Access
FirstName Ka Wah Mei Lee Chun Kit Charles
LastName Chan Wong Chan Li
Gender M F M M
Married Y N Y N
Birthday 03-Sep-86 12-Dec-80 02-Jan-83 03-Mar-86
Address1 6A, Blk 2 Rm 711, Blk 21 8/F, Tai Wah 7B, Blk 4
Bldg
Address2 23, Wing On Wah Fu Estate 11, Water Road 44, Ming Tak
Street Street
District Mong Kok Aberdeen Sheung Wan Shatin
Region Kowloon Hong Kong Hong Kong N.T.
Performance 195 220 180 120
Salary 22000 45000 33000 11000
Position EO LA AL CO
3. Close Datasheet View.
4. Create a data entry form for Employee using Form Wizard.
5. Save the form as Employee Form and insert the following 4 extra records using it.
Name Record 5 Record 6 Record 7 Record 8
EmployeeID The value here is automatically assigned by MS Access
FirstName Kwai Ming Man Yee Kar Ling Chi Shun
LastName Luk Hung Chan Mak
Gender M F F M
Married N N Y Y
Birthday 12-Nov-79 02-Feb-91 13-Apr-84 12-Aug-83
Address1 Rm 813, Blk 1/F, Chi Yun Flat G, 6/F 2/F, Tai Nam
22 Bldg Bldg
Address2 Nam Fung 981, King’s Rd 4, Waterloo Rd Tai Nam Street
Estate
District Shatin Quarry Bay Yau Ma Tei Sham Shui Po
Region N.T. Hong Kong Kowloon Kowloon
Performance 85 50 165 200
Salary 15000 11000 35000 20000
Position PS CO AL EO
6. Save the records and then close the form. Open Employee again in Datasheet
View to check if the 4 extra records are added by Employee Form successfully or not.
13