Lab 03
Lab 03
3.1.1 Objectives
By the end of this laboratory session you should:
1. Be able to demonstrate the following Microsoft Access skills:
Add customised functionality to a form by including a subform.
Undertake maintenance on a form to meet requirements changes.
2. Have completed the following steps in the Video rentals System development:
Built a form and facilitating the video check-out process.
Added a gender field to the Member table.
Built a form for adding and editing video details.
3. Have gained an understanding of the following concepts:
Forms with subforms can provide a convenient means of manipulating data stored in
multiple tables.
Development tools such as Microsoft Access allow the developer to add extra
functionality to forms by means of program code.
Minor modifications can be made to the data structure of a system after the initial
construction has begun.
3.2 Exercises
3.2.1 The Rental Process
Consider the process of a member hiring a video. The following events need to occur in the system
as a member comes to the counter, presents their card and video(s) to be hired:
1. The member's identity needs to be verified i.e. that the number on their card does actually exists
in the database1 in the Member table.
2. A new record needs to be added to the hire table containing the member’s ID, the video code,
the date on which it was hired, and the date it is due to be returned.
3. The status field for the video in the Video table needs to be set to false.
Manually renting out a video
1
In practice other checks would be made, such making sure that the member does not have any overdue videos etc.
However that is beyond the scope of this simplified system.
1
In order to fully appreciate what data needs to be inserted and altered in the tables when a video is
rented out, manually record a rental as follows:
Open the Hire table and add a new record. Select the video code from the drop down list,
and a member from the drop down list on the Member_ID field. Enter today's date for the
Date of the Loan, and some suitable future date for the Due Date.
Open the Video table and remove the tick from the Available field for any video of your
choice that is not already out on hire.
Note how a hire number is generated automatically. Leave the remaining fields blank.
Automating the Rental Process
In this section, you will create a Rental form (refer to Figure 3.1) to automate the rental process. It is
actually two forms: a main form which is based on the Member table and a subform which draws
data from the Video and Hire tables. The two forms are linked together, by a common field, namely
the Member_ID which is stored in both the Member and Hire tables. Have a look at the
relationships between the tables again (from the Tools menu select Relationships). The Member_ID
is not displayed on the subform, but it must be there in order to link the member to the hire.
In order to meet the requirements listed in points two and three above, it is necessary to go beyond
the default functionality available in Microsoft Access by writing some Visual Basic code in order to
store the due date and set the video status to false.
Microsoft Access is an event-driven programming environment, i.e. when something happens (an
event, such as pressing a button, opening a form, or selecting an item from a combo box), a response
is triggered. For example, in the previous laboratory session, a button being pressed resulted in
another form being opened.
2
Consider the operation of the form during the rental process: The user selects the member from the
combo box on the main form. The video code of the video about to be rented is then selected from a
combo box on the video code field in the subform. This combo box displays only those videos that
are available for hire - not those already out on hire. When the video is selected, its status needs to
be set to false. The member’s id, the video code, the date of the loan and the due date need to be
stored in the loan table.
Building on an existing form
The main form shown in Figure 3.1 is just about identical to the Member form created in last week’s
session. To save unnecessary duplication of effort, you will make a copy of this form, modify some
its properties and insert a subform. You could create the subform independently, but Microsoft
Access supplies a wizard that enables you to create it starting from within the main form.
1. Open your Video rentals System Microsoft Access database from last week’s session.
2. Make a copy of the Member form and named as “Video Rentals”
3. Delete the address fields, change form's Caption and the Label at the top of the form
The purpose of the Video Rentals form is to enter and view rental data. The member’s details on this
form should not be able to be changed. Therefore, you will lock the viewable fields in the member’s
section of the form (i.e. Member_ID, Title, Surname, and First_Name).
4. Change appropriate properties for locking and disabling the Member_ID, Title, Surname,
and First_Name fields. What is the difference between these two properties?
__________________________________________________________________
5. Use the control toolbar to add a Subform/Subreport control in the space at the bottom of the
form (refer to Figure 3.2). Use the following information to respond to the wizard:
(a) Use data from existing Tables and Queries.
(b) Select the Current Rentals query and add all the fields.
(c) Select the “Show Current Rentals for each record in Member using Member_ID”
link.
(d) Give your subform an appropriate name (e.g. “Video Rentals subform”).
3
Figure 3.2: Adding the Video Rentals subform
6. Run the form (i.e. change from the design view to the form view). Notice the subform is in a
different view, known as the Datasheet View.
7. The Hire_Num and Member_ID are important fields for the functioning of the form, but do
not need to be seen by the user2. Therefore, when the form is open, right-click on the two
columns and select “Hide Columns”.
8. Make the necessary modifications to the Video Rental subform to resemble that shown in
Figure 3.1. Note that you can get to the subform properties in a similar way to getting to the
form properties (i.e., using the shortcut).
Limiting the form to only Videos available for rental
Currently, when you select the “Video Code” drop down box to enter a new rental, all the possible
rentals are listed. In this section, you will limit the list to only videos that are able to be hired.
1. Select the Row Source property of the Video_Code in the Video Rentals subform. Click on
the ellipsis and as you do so you will invoke the query builder on the Video table.
2. Create (and save) a query with satisfies the following criteria:
Include the Video_Code, Title and Status fields.
Enter an appropriate criterion for the Status field, so only videos available to be
borrowed are selected.
There is no need to show the Status field.
3. Save the changes and close the query builder.
4. Test the changes to the Video_Code drop down box.
Implementing the rental process
1. Try hiring a video (Remember to first select a member on the main form). Check the Hire
table and confirm that a new record has been created. What needs to be changed to complete
the rental?
2. Delete any incomplete rentals from the Hire table.
In order to complete the rental, you need to write some code to enter an appropriate Due_Date and
change the availability of the video status to “False”.
3. Reopen the subform in design mode and select the After Update event of the Video_Code
properties. When do you expect the After Update event will be executed? Use the online
help to verify you assumption.
4. Using the ellipsis, select “Code Builder”. Notice how the Microsoft Visual Basic
development environment is opened.
5. Between the existing code enter the following3 :
2
The reason why will become apparent later in the course
3
What needs to happen to the status field when a video is returned? The process of returning videos happens elsewhere
in the system, perhaps in another program altogether. What does this imply about the development and maintenance of
the system? (You'll learn the answer to this later in the course)
4
'Changes the video status to unavailable.
[Status] = False
'Enters the due date as 7 days from the current 'date.
[Due_Date] = Date + 7
Note: The lines of code starting with an apostrophe ' are comments for the developer, and are not
executed when the program is run.
6. Close the Microsoft Visual Basic development environment and test the code by hiring out a
video. Is the status of the video you have hired out set to false? Has a new record been
created in the hire table with the appropriate hire date and due date?
Evaluation of the Video Rental form
To ensure a quality system, it is important to evaluate the forms and reports you have created. In this
section, you will evaluate the Video Rental form based on your understanding of a standard Video
Store’s requirements.
1. Use the following questions to help you evaluate the Video Rental form:
Can you identify any limitations in this form?
___________________________________________________________________
What functionality do you expect is missing from the form?
___________________________________________________________________
What improvements could be made to make the form more usable (i.e. easier for
people to use)?
____________________________________________________________________
5
Attach the Text Box to the Gender field in the Member table by using the Control
Source property.
Add an appropriate Label.
Adjust the formatting of the Text Box and Label to be consistent with the other
controls on the form.
3.2.5 Review
In this week's laboratory session you have:
1. Experienced how a form with a subform can display data from multiple tables
2. Gained experience in writing some simple code to enhance the functionality of a form to
meet the specific needs of a given application.
3. Gained experience in modifying existing components of an information system in order to
meet changing user requirements.
END OF LAB. 3