|
Example Database: The Ceil Inn Hotel |
|
|
Ceil Inn is a (fictional) hotel. The company provides
various types rooms (bedrooms, suites, and conference rooms). Rooms have
different types of bed (queen, double, or king). Depending on the type of
room and the bed(s), a certain rate is charged to occupy or use a room.
|
We are asked to create a database application that
would help the employees of Ceil Inn to manage their business.
Practical
Learning: Starting the Application
|
|
- Start Microsoft Access
- In the opening window, change the File Name to CeilInn1
- Click Create
- Click File and click Options
- Click Current Database
- Click Overlapping Windows
- Click Compact On Close
- Click Remove Personal Information From File Properties On Save
- Click OK
- Click OK.
If you want, close Microsoft Access (you don't really
have to, but the screen shots in this lesson will use overlapping
windows), then re-start it and open the CeilInn1 database
The Employees of the Company
|
|
Employees are people who will manage all aspects of
the database. In most databases, they are identified with as much
information as possible. To keep our implication simple, we will need the
name and the title of each employee. To uniquely identity an employee,
each one will have an employee number. This number will be specified but
the person who is creating the record for a new hire.
Practical
Learning: Creating the Employees
|
|
- On the Ribbon, click Create
- To create a new table, in the Tables section, click the Table
Design
- Click under Field Type and type EmployeeNumber
- Press Tab and accept its Data Type as Text.
While the field is
still selected, in the Tools section of the Ribbon, click the
Primary Key button
- In the lower section of the window, set the Field Size to
20
- In the top section of the window, click under EmployeeNumber
- Complete the list of fields as follows:
Field Name |
Data Type |
Caption |
Field Size |
EmployeeNumber |
Text |
Employee # |
20 |
FirstName |
Text |
First Name |
25 |
LastName |
Text |
Last Name |
25 |
Title |
Text |
|
50 |
Notes |
Memo |
|
|
- To close and save the table, right-click Table1 and click Close
- When asked whether you want to save the table, click Yes
- Set the name to Employees and
- Click OK
- To create a form for the room types table, on the Ribbon, click
Create and, in the Forms section, click Form Design
- Save the form as Employees
- Using the Properties window, set its Record Source as Employees
- Design the form approximately as follows:
- Save the form and switch it to Form View
- Close the form
The Customers of the Hotel
|
|
The customers are the people who rent the rooms that
the hotel offers. Like employees, customers have to be identified. For our
database, we will just need each customer's name, the telephone number,
and information about a person to contact in case of emergency.
When a customer comes to rent a room, an account will
be created for him or her. If the same customer comes to rent a room
another time, a new accuont will be created. This means that, for
accounting purposes, we will need a unique account number for each renting
session, even for a repeating customer.
Practical
Learning: Creating the Customers
|
|
- On the Ribbon, click Create
- To create a new table, in the Tables section, click the Table
Design
- Click under Field Type and type AccountNumber
- Press Tab and accept its Data Type as Text.
While the field is
still selected, in the Tools section of the Ribbon, click the
Primary Key button
- In the lower section of the window, set the Field Size to
20
- In the top section of the window, click under AccountNumber
- Complete the list of fields as follows:
Field Name |
Data Type |
Caption |
Field Size |
AccountNumber |
Text |
Account Number |
20 |
FirstName |
Text |
First Name |
25 |
LastName |
Text |
Last Name |
25 |
PhoneNumber |
Text |
Phone Number |
20 |
EmergencyName |
Text |
Emergency Name |
50 |
EmergencyPhone |
Text |
Emergency Phone |
20 |
Notes |
Memo |
|
|
- To close and save the table, right-click its title bar and click
Close
- When asked whether you want to save the table, click Yes
- Set the name to Customers and
- Click OK
The Ceil Inn hotel offers different categories of
rooms. A regular bedroom is equipped with one or two beds, one table, one
sofa or recliner, two chairs, a closet, and an iron. Besides being a place
to sleep, the room has a telephone (analogue line), a kitchen area that
has a stove, a refrigerator, a dish washer, and cabinets. The cabinets
contain spoons, forks, knives, and plates.
For our database, we will need a table named Room
Types.
Practical
Learning: Creating the Types of Rooms
|
|
- On the Ribbon, click Create
- To create a new table, in the Tables section, click the Table
Design
- Click under Field Type and type RoomType
- Press Tab and accept its Data Type as Text.
While the field is
still selected, in the Tools section of the Ribbon, click the
Primary Key button
- In the lower section of the window, set the Field Size to
25
- In the top section of the window, click under RoomType and type
Notes
- Press Tab and type m and make sure Memo is selected
- To close and save the table, double-click the Table1 icon
- When asked whether you want to save the table, click Yes
- Set the name to RoomTypes and
- Click OK
- To create a form for the room types table, on the Ribbon, click
Create and, in the Forms section, click Form Design
- Save the form as RoomTypes
- Using the Properties window, set its Record Source as RoomTypes
- Design the form approximately as follows:
- Save the form and switch it to Form View
- Close the form
Most of the business of Ceil Inn hotel is based on
rooms the customers rent, and most customer rent a room to spend the
night. To serve such customers, bedroom have different types of bed. The
most common bed has a queen size that can serve one or two people. Another
category of room uses a king size, which is larger and wider than the
queen. Some customers wants a single room but with different beds. Such
rooms have a double bed. Of course, conference rooms do not have a bed.
Practical
Learning: Creating the Types of Beds
|
|
- On the Ribbon, click Create
- To create a new table, in the Tables section, click the Table
Design
- Click under Field Type and type BedType and press Tab
- Right-click BedType and click Primary Key
- In the lower section of the window, set the Field Size to
25
- In the top section of the window, click under BedType and type
Notes
- Press Tab and type m and make sure Memo is selected
- To close and save the table, right-click Table1 and click Close
- When asked whether you want to save the table, click Yes
- Set the name to BedTypes and
- Click OK
- To create a form, on the Ribbon, click Create and, in the Forms
section, click Form Design
- Save the form as BedTypes
- Using the Properties window, set its Record Source as BedTypes
- Design the form approximately as follows:
- Save the form and switch it to Form View
- Close the form
The Occupancy Status of a Room
|
|
The hoteil has different rooms that are rented or
freed some time to time. When a room is not rented, it has the status of
available. When a room has been rented, its occupancy status must be
changed to occupied. To take care of this, we will create a table for
rooms status.
This is the idea behind a relational database. A
relational database is an application that contains two or more tables so
that information in one table is made available to another table or other
tables that need(s) it. The information is entered once in one particular
table. If the same information is needed in another table, it is simply
identified one way or another. This reduces, and can eliminate, the
likelihood of mistakes that result from duplicate data.
Practical
Learning: Creating the Occupancies Status of Rooms
|
|
- On the Ribbon, click Create
- To create a new table, in the Tables section, click the Table
Design
- Click under Field Type and type RoomStatus and press Tab
- Right-click BedType and click Primary Key
- In the lower section of the window, set the Field Size to
30
- In the top section of the window, click under BedType and type
Notes
- Press Tab and type m and make sure Memo is selected
- To close and save the table, right-click Table1 and click Close
- When asked whether you want to save the table, click Yes
- Set the name to RoomsStatus and
- Click OK
- To create a form, on the Ribbon, click Create and, in the Forms
section, click Form Design
- Save the form as RoomsStatus
- Using the Properties window, set its Record Source as RoomsStatus
- Design the form approximately as follows:
- Save the form and switch it to Form View
- Close the form
Rooms are probably the most important objects of a
hotel. A room is primarily characterized by its category as a bedroom or a
conference room. If it's a bedroom, then other pieces of information are
necessary. We have already seen what they are: bed type and status.
Each room must have a unique room number. The rate
applied when renting a room should be specified. After all, en employee
should not guess the price of a room when a customer is about to rent it.
Practical
Learning: Creating the Rooms
|
|
- On the Ribbon, click Create. In the Tables section, click the
Table Design
- Set the name of the first field to RoomNumber and press Tab
- Right-click RoomNumber and click Primary Key
- To save the table, right-click Table1 and click Save
- Set the name to Rooms and click Save
- Click under RoomNumber
- Type RoomType and press Tab
- Press L and press Tab
- In the first page of the wizard, make sure the first radio button
is selected and click Next
- In the list of tables, click RoomTypes and click Next
- Double-click RoomType and click Next
- Click Next
- Click Finish
- When asked to save the table, click Yes
- Click under RoomType
- Type BedType and press Tab
- Type L and press Tab
- In the first page of the wizard, make sure the first radio button
is selected and click Next
- In the list of tables, click BedTypes and click Next
- Double-click BedType and click Next
- Click Next
- Click Finish
- When asked to save the table, click Yes
- Click under BedType and type Rate
- Click Rate and type RoomStatus
- In the corresponding Data Type, select Lookup Wizard
- In the first page of the wizard, make sure the first radio button
is selected and click Next
- In the list of tables, click RoomsStatus and click Next
- Double-click RoomStatus and click Next
- Click Next
- Click Finish
- When asked to save the table, click Yes
- Complete the table as follows:
Field Name |
Data Type |
Caption |
Field Size |
Format |
RoomNumber |
Text |
Room Number |
10 |
|
RoomType |
Text |
Room Type |
|
|
BedType |
Text |
Bed Type |
|
|
Rate |
Number |
|
Double |
Fixed |
RoomStatus |
Text |
Status |
|
|
Notes |
Memo |
|
|
|
- Save the table
- Close it
- To create a form for the rooms table, on the Ribbon, click Create
- In the Forms section, click Form Design
- Save the form as Rooms
- In the Properties window, set the Record Source to Rooms
- Design the form approximately as follows:
- Save the form
After registering a customer, the employee can assign
a room. Normally, th employee would ask what type of room the customer
wants to rent. After all some people want a bedroom, others a studio, and
others a conference room. The employee can (create or) use a query that
shows only the available rooms:
Probably a better way is to create a form that would
show the list of available rooms.
When assigning a room to a customer, we first need to
know who (the employee) performed this operation. We also would like to
know the date when this operation was performed. We may just use that same
date as the first day a customer rented a room or the day a conference
room was used. Of course, the employee needs to identify the customer who
is renting the room. The employee must also specify the room that is being
rented and how much will be charged. To know the rate, the employee can
use the same query or form mentioned previously for available rooms.
In our hotel, the Internet is free to all customers
(we remember when hotels used to charge for Internet use; most of them now
offer free Internet and many of them have computers somewhere at the
receiption or in some room for customers use). If using the telephone in
the room, if a customer makes local calls, they are free. Long distance
calls are not free. We need to keep, on a daily basis, a calendar and rate
of phone consumption (this is one of the reasons we create a new account
for every customer, including returning customer).
As you can imagine, each room assignment must have a
unique number that identifies its record. We will use an automatically
incrementing number. To make it a little fancy, we will start the
numbering at 100001 and increment by 1 for each subsequent record.
Practical
Learning: Assigning a Room
|
|
- On the Ribbon, click Create
- In the Forms section, click Form Design
- Using the Properties window, change the following characteristics
of the form
Default View: Continuous Forms Record Selector: No
Navigation Buttons: No
- Save the form as AvailableRooms
- In the Properties window, click Record Source and click its
ellipsis button
- In the Show Table dialog box, click Rooms
- Click Add and click Close
- In the list of fields, double-click RoomNumber, RoomType, BedType,
Rate, and RoomStatus
- In the lower section of the window, click the box at the
intersection of RoomStatus and Criteria
- Type Available
- Close the Query Builder
- When asked whether you want to save, click Yes
- Design the form approximately as follows:
|
Control |
Name |
Caption |
Back Color |
Control Source |
Label |
|
|
Available Rooms |
|
|
Line |
|
|
|
|
|
Label |
|
|
Room # |
|
|
Label |
|
|
Room Type |
|
|
Label |
|
|
Bed Type |
|
|
Label |
|
|
Rate |
|
|
Text Box |
|
RoomNumber |
|
|
RoomNumber |
Text Box |
|
RoomType |
|
|
RoomType |
Text Box |
|
BedType |
|
|
BedType |
Text Box |
|
Rate |
|
|
Rate |
|
- Save and close the form
- On the Ribbon, click Create and, in the Queries section, click
Query Design
- In the Show Table dialog box, click Close
- Right-click the top section of the window and click SQL View
- Type the following code:
CREATE TABLE Occupancies
(
OccupancyNumber Counter(100001, 1) not null
);
- To exexcute, in the Results section of the Ribbon, click the Run
button
- Close the Query window
- When asked whether you want to save, click No
- In the Navigation Pane, right-click Payments and click Design View
- Right-click ReceiptNumber and click Primary Key
- Complete the table as follows:
Field Name |
Data Type |
Caption |
Field Size |
Format |
OccupancyNumber |
|
Occupancy Number |
|
|
EmployeeNumber |
Text |
Processed By |
20 |
|
DateOccupied |
Date/Time |
Date Occupied |
|
Long Date |
AccountNumber |
Text |
Processed For |
20 |
|
RoomNumber |
Text |
Room # |
10 |
|
RateApplied |
Number |
Rate Applied |
Double |
Fixed |
PhoneCharge |
Number |
Phone Charge |
Double |
Fixed |
Notes |
Memo |
|
|
|
- Close and save the table
- To create a form, on the Ribbon, click Create and, in the Forms
section, click Form Design
- Save the form as Occupancies
- Using the Properties window, set its Record Source as Occupancies
- Design the form approximately as follows:
|
Control |
Name |
Caption |
Back Color |
Control Source |
Label |
|
|
Ceil Inn: Payment |
|
|
Label |
|
|
Receipt #: |
|
|
Text Box |
|
ReceiptNumber |
|
|
ReceiptNumber |
Label |
|
|
Payment Date: |
|
|
Text Box |
|
PaymentDate |
|
|
PaymentDate |
Label |
|
|
Processed By |
Text Light |
|
Label |
|
|
Employee #: |
|
|
Text Box |
|
EmployeeNumber |
|
|
EmployeeNumber |
Text Box |
|
txtEmployeeName |
|
|
=IIf(IsNull([EmployeeNumber]),"",DLookUp("LastName","Employees","EmployeeNumber
= '" & [EmployeeNumber] & "'") & ", " &
DLookUp("FirstName","Employees","EmployeeNumber = '" &
[EmployeeNumber] & "'")) |
Label |
|
|
Occupyer Information |
Text Light |
|
Label |
|
|
Customer Acnt #: |
|
|
Text Box |
|
AccountNumber |
|
|
AccountNumber |
Label |
|
|
Phone #: |
|
|
Label |
|
|
Customer Name: |
|
|
Text Box |
|
txtCustomerName |
|
|
=IIf(IsNull([AccountNumber]),"",DLookUp("LastName","Customers","AccountNumber
= '" & [AccountNumber] & "'")+',
'+DLookUp("FirstName","Customers","AccountNumber = '"
& [AccountNumber] & "'")) |
Text Box |
|
txtPhoneNumber |
|
|
=IIf(IsNull([AccountNumber]),"",DLookUp("PhoneNumber","Customers","AccountNumber
= '" & [AccountNumber] & "'")) |
Label |
|
|
Room Information |
Text Light |
|
Label |
|
|
Date Occupied |
|
|
Text Box |
|
DateOccupied |
|
|
DateOccupied |
Label |
|
|
Room #: |
|
|
Text Box |
|
RoomNumber |
|
|
RoomNumber |
Label |
|
|
Room Type: |
|
|
Text Box |
|
txtRoomType |
|
|
=IIf(IsNull([RoomNumber]),"",DLookUp("RoomType","Rooms","RoomNumber
= '" & [RoomNumber] & "'")) |
Label |
|
|
Bed Type: |
|
|
Text Box |
|
txtBedType |
|
|
=IIf(IsNull([RoomNumber]),"",DLookUp("BedType","Rooms","RoomNumber
= '" & [RoomNumber] & "'")) |
Label |
|
|
Regular Rate: |
|
|
Text Box |
|
txtRegularRate |
|
|
=IIf(IsNull([RoomNumber]),"",DLookUp("Rate","Rooms","RoomNumber
= '" & [RoomNumber] & "'")) |
Label |
|
|
Rate Applied: |
|
|
Text Box |
|
RateApplied |
|
|
RateApplied |
Label |
|
|
Notes: |
|
|
Text Box |
|
Notes |
|
|
Notes |
|
- Using the Button control
in the Ribbon, add a button to the Footer section of the form. In the
first page of the wizard, select Form Operations and Open Form then
click Next. In the second page of the wizard, click AvailableRooms and
click Finish
- Save the form and switch it to Form View
- Close the form
- To create another form, in the Navigation Pane, right-click
Occupancies and click Copy
- Right-click any section in the Navigation Pane and click Paste
- Type the name as NewOccupancy
- Click OK
- In the Navigation Pane, right-click NewOccupancy and click Design
New
- Using the Properties window, change the following characteristics
of the form:
Modal: Yes Auto Center: Yes Border Style: Dialog
Navigation Buttons: No Data Entry: Yes
- Change the design of the form as follows:
- Save the form and switch it to Form View
- Close the form
- On the Ribbon, click Create
- In the Forms section, click Form Design
- Right-click the body of the form and click Form Header/Footer
- Save the form as sfOccupancies
- Using the Properties window, change the following characteristics
of the form
Default View: Continuous Forms Record Selector: No
Navigation Buttons: No
- In the Properties window, set the Record Source to Occupancies
- Click the Form Footer bar and, in the Properties, set its Visible
field to No
- Design the form approximately as follows:
|
Control |
Name |
Caption |
Control Source |
Label |
|
|
Date Occupied |
|
Label |
|
|
Room # |
|
Label |
|
|
Rate |
|
Label |
|
|
Phone Use |
|
Text Box |
|
DateOccupied |
|
DateOccupied |
Text Box |
|
RoomNumber |
|
RoomNumber |
Text Box |
|
RateApplied |
|
RateApplied |
Text Box |
|
PhoneCharge |
|
PhoneCharge |
Text Box |
|
txtRateTotal |
|
=Sum([RateApplied]) |
Text Box |
|
txtPhoneUse |
|
=Sum([PhoneCharge]) |
|
- Save and close the sub-form
- On the Ribbon, click Create
- In the Forms section, click Form Design
- In the Properties window, change the Record Source to Customers
- Save the form as Customers
- In the Controls section of the Ribbon, click Subform/Subreport
and click the body of the form
- In the first page of the wizard, click the Use An Existing Form
radio button and click sfOccupancies
- Click Next
- In the second page of the wizard, make sure Show Occupancies For
Each Record In Customers Using AccountNumber is selected.
Click
Next
- Type Room Occupany Summary
- Click Finish
- Design the form approximately as follows (we will list only three
new text boxes you should add to the form and whose Control Source
doesn't depend directly on the Customers table):
|
Control |
Name |
Caption |
Back Color |
Control Source |
Label |
|
|
Room Use: |
|
|
Text Box |
|
txtRoomUse |
|
|
=[sbfOccupancies].[Form]![txtRateTotal] |
Label |
|
|
Phone Use: |
|
|
Text Box |
|
txtPhoneUse |
|
|
=[sbfOccupancies].[Form]![txtPhoneUse] |
Label |
|
|
Total: |
|
|
Text Box |
|
txtTotal |
|
|
=Nz([txtRoomUse])+Nz([txtPhoneUse]) |
|
- Save and switch it to Form View
- Close the form
|
|