Unit 7 - Using Forms To Update and Modify Data in A Database
Unit 7 - Using Forms To Update and Modify Data in A Database
7
Using Forms to Update and
Modify Data within a Database
Source:http://tinyurl.com/zsm25z6
Overview
5. Describe the various form controls that may be used to enhance a form;
Session 7.2: Modifying a form design to enhance data collection and the user
interface
Required Textbook
Miller, Lisa. (2008). MIS Cases: Decision making with application software (3rd
Edition). Pearson Education Inc, Upper Saddle River, New Jersey
Additional Resources
Introduction
In Unit 5, we reviewed creating tables and adding and editing data within tables.
We, however, used the datasheet view to add and edit data within the tables. Access
allows for the use of more user-friendly objects to allow for modifying data, these
objects are known as forms.
Forms in Access are like display cases in stores that make it easier to view or get the
items that you want. Since forms are objects through which you or other users can add,
edit, or display the data stored in your Access desktop database, the design of your
form is important. If your Access desktop database is going to be used by multiple
users, well-designed forms are essential for efficiency and data entry accuracy. In this
session, we will review how to create a form in an Access database.
About Forms
A Form is an Access object that allows the end user to add, edit and display data in
the database. In most databases, forms are usually provided for end users to use when
interacting with the database as they make it easier to view, add, edit and delete data
within the database. Forms may be built using tables or queries within the database,
but are commonly used with tables. Given this, it is therefore important to ensure that
forms are appropriately designed to enhance user-friendliness.
Command buttons and other functionalities may be added to a form to make it easier
to perform operations within the database.
Creating Forms
There are several ways to create a form in an Access database. This unit will focus
on creating forms using the Form Wizard and creating forms directly from tables or
queries. Once a form has been created, you can modify the form by adding additional
fields and design controls to enhance the forms.
ACTIVITY 7.1
Create a Database (30 minutes)
Instructions:
3. Using the information contained in Figure 7.1 below, Create the Student
Table.
4. Using the information contained in Figure 7.2 below, Create the Course
Table.
To create a form from a table (or query) using the Form Wizard:
4. On the first page of the wizard, in the Tables/Queries drop-down list, select a
table or query. We will select the Student table first.
5. Double-click the fields that you want to include from this table. For this
demonstration, we want to include all the fields in the Student table. The single
arrow will allow you to add one field at a time, while the double arrow will allow
you to add all fields in the selected Table (Query).
6. Click Next
8. Click Next.
9. Enter a Title for the Form. By default, Access will insert the name of the Table (or
query) on which the form was based.
10. You can now decide whether to Open the form in Form view, so that you can view
or enter information, or you may open the form in Design view, where you can
modify the form’s design.
12. The form will open in Form View and will display the first record in the Student
Table.
• The Form Header contains general information about the form; for example, if
you were working in a company database, the name of the company the form is
associated with and the name of the form.
• The Detail Section usually contains most controls including the text boxes linked
to the table or query and the appropriate labels. Labels and text boxes and other
controls will be discussed in Session 7.4.
• The Form Footer often contains general information for the form such as contact
information.
In Learning Activity 7.2 you will view a presentation which further explores creating
forms within a database.
Instructions:
Use this video to explore and learn more about creating forms within an
Access database.
In Learning Activity 7.3 you will further explore creating forms within a database
using the Form Wizard.
ACTIVITY 7.3
Creating Forms in an Access Database using Form Wizard (15
minutes)
Instructions:
Open the StudentRegDB database and using the Form Wizard, create
a form based on the Course Table.
The Form Wizard can create a variety of results depending on the options that you
select. As practice, it is recommended that you run the Form Wizard several times,
experimenting with different options each time, until you get the desired results.
2. Identify the existing table (or query) in the Navigation Pane that contains the data
required for the form.
5. Access will then create a form containing all the fields in the Table (or query)
selected and displays the form in Layout view. You can now make design changes
as desired.
In Learning Activity 7.4 you will further explore creating a form directly from a Table
within a database.
ACTIVITY 7.4
Creating Forms in an Access Database using Form Wizard (15
minutes)
Instructions:
Open the StudentRegDB database and using the steps outlined above,
create a form based on the Registration Table. (Do not use the Form
Wizard).
In Learning Activity 7.5 you will view a presentation which further explores working
with forms to enter, edit and delete records within a database.
ACTIVITY 7.5
Working with Forms in an Access Database (30 minutes)
Instructions:
Watch the VIDEO entitled “Working with Forms” located on the webpage:
In this session we reviewed creating and using forms to collect and store data in a
database. Now that we have our forms, in the next session, we will look at enhancing
our forms’ user interface.
Introduction
After creating your form, it may become necessary to modify the form design in order
to enhance the user interface and make it easier to facilitate data collection. Most
designs to a form will take place in the Design View. In this session we will review the
most frequently used methods that may be adopted to further enhance a form’s design
and how to apply good design techniques based on best practices when developing
forms.
Design View
The Design View provides a detailed view of the structure of a form. From this view,
you will see the Header, Detail, and Footer sections of the form. The form is not active
when it is shown in Design View; therefore, you will not be able to see the underlying
data while in Design View.
Modify a Form
There are several tasks that you may want to effect to enhance the design of your form.
These you would perform in the Design View of the form (as opposed to Form View
and Layout View).These include:
• Adding and editing controls on your form (this will be discussed further in Session
7.4).
• Resizing sections on the form, such as the Form Header or the Detail section.
• Adding details to the section of the form.
• Changing certain form properties that cannot be changed in Layout view.
Change the Size of a Field:
1. Open the form in Design View.
3. To change the width of the control: Click and hold on to a side of the control
(preferably the right side) and drag to change the width of the control.
4. To change the height of the control: Click and hold on to the top or bottom of a
control and drag to change the height of a control.
Move a Control:
1. Open the form in Design View.
2. Hang the mouse at the side of a control until the four-sided arrow appears.
3. Click and hold on to the control (preferably the right side) and drag and move the
control in the desired direction.
While layouts can help to quickly modify a form, in some cases, you may need to
move and size the controls independently. To do this, you would need to remove
controls from layouts, after which you can move and resize them without affecting
other controls.
To do this:
3. Select the controls on the form that should be removed from the layout.
3. Provide directions on the form, where necessary, so that the user knows how to
use the form.
4. Ensure that the form has an appropriate layout that is easy for the user to understand
and to navigate.
9. Use the tools and features available to assist with data validation.
In Learning Activity 7.6 you can view the presentation to further explore formatting
forms within a database.
ACTIVITY 7.6
Working with Forms in an Access Database (30 minutes)
Instructions:
uu https://youtu.be/DX0vI__-Bgs
Use this video to explore and learn more about working with and
formatting forms within an Access database.
In this session we explored ways in which we can modify a form to enhance its user
interface and apply good design techniques. In the next session, we will review the
use of subforms.
Introduction
Recall that with relational databases, the data are stored in separate tables within
the database. In session 7.1, we learnt how to create a form from one table. It may
become necessary to create a form from multiple tables or queries so that data may be
viewed from these multiple sources. This may be accomplished using a subform. In
this session we will learn how to create a form with a subform.
Subforms
A subform is a form within another form. The primary form is called the main form. A
combination of a form and a subform is sometimes referred to as a hierarchical form
or a parent/child form.
Subforms are especially useful when you want to show data from tables or queries
that have a one-to-many relationship. For example, using our StuRegDB database,
you may want to see a student’s record from the Student table and additional data
about that student from the Course table, both at the same time. The data in the
Student table is the “one” side of the relationship while the data in the Course table
is the “many” side of the relationship (each student can be registered for more than
one course).
In our example, we will create a Student form that displays the students and the
course(s) they are registered for in a subform.
4. On the first page of the wizard, in the Tables/Queries drop-down list, select a
table or query. We will select the Student table first.
5. Double-click the fields that you want to include from this table. We want to include
all the fields in the Student table.
6. Then, (on the same page of the wizard), in the same Tables/Queries drop-down
list, select another table or query from the list. This time we will select the Course
table.
7. Double-click the fields that you want to include from this table. We want to include
all the fields in the Course table except the Student ID (this field was already
included from the Student table).
8. Click Next
9. The wizard will then ask: How do you want to view your data? - that is, by which
table. We want to view by the Student table, select Student.
11. Select Form with subform(s) (this is located at the bottom of the wizard page).
13. Do not change the layout, allow it to remain on the default layout – Datasheet.
15. Type the titles that you want for the forms. Access will name the form based on the
titles typed, and label the subform based on the title that you type for the subform.
We will title our Form: Student Form and the Subform: Course Form.
18. Access then creates two forms - one for the main form that contains the subform
control, and one for the subform itself. The subform control is the control that
embeds a form into a form. The main form is linked to the Student table and the
subform is linked to the Course table.
5. On the Design tab, in the Controls group, click the down-arrow to display the
Controls gallery.
6. On the Design tab, in the Controls gallery, click the Subform/Subreport button.
7. Click the section on the form where you want to place the subform.
8. The Subform Wizard will open. Follow the directions in the wizard (similar to the
steps carried out above when creating a subform).
9. When you click Finish, Access will add a subform control to your form.
In Learning Activity 7.7 you will practice creating a form and a subform.
ACTIVITY 7.7
Create a Form and a Subform (30 minutes)
Instructions:
1. Using the StuRegDB database, create a Student Form with the Registration
Form as a subform. You are free to use either of the two methods outlined
above.
2. Save your database and upload your database to the appropriate forum
in the Learning Exchange.
In this session, we learnt how to create a form from a table whose records are linked
to another table, thereby creating a subform. Subforms allow for the viewing of
data across multiple tables. In the next session, we will learn how to create the most
commonly used controls on forms so as to enhance the user interface.
Introduction
Controls help to set restrictions on the fields in database forms. This helps to better
control how the data is entered into your database via the form and helps to maintain
consistency within the database, for example, combo boxes. A combo box is a control.
Controls may also be used to enhance the form so as to make it more user-friendly
and easier for the user to navigate, for example, control buttons. A control button is a
control. In this session we will learn how to create the most commonly used controls
on forms so as to enhance the user interface.
Controls
There are several different types of controls that may be used on forms. The available
controls may be found on the Design tab in the Controls grouping. We will explore
the most frequently used controls, such as Text Box, Label, Button and Combo Box. In
session 7.3 you explored the subform control.
Text Box
A text box is represented by a rectangular box which allows you to view, type, or edit
text or data that is usually bound to a field from a table or a query. For example, when
you create a form, the rectangular boxes that contain the data from the fields are the
text boxes. When you add a text box a label is also created along with the text box.
5. Select the desired location on the form where you would like to place the Text Box
and click (using the left click).
6. The Text Box will be placed on the form. You may now bound the Text Box to a
field in a table or a query. A Label control has also been provided so you may edit
the text in the Label as appropriate.
Label
A label is used to add descriptors to your form. For example, you would use a label
to identify the contents of a text box, or to display descriptive text or instructions to
the user. These include, titles, captions, and pictures. When you create a form, Access
automatically adds labels beside each text box. Recall that the text box will be bound
to a field; the labels would have a similar name as the text box. You can always edit
the names (text) in the label.
To create a Label:
6. Select the desired location on the form where you would like to place the Label
and click (using the left click) and hold down the left click and drag your hand
across as far as you want the label to extend.
7. The Label will be placed on the form. The cursor will be blinking in the Label; you
may now enter the text in the Label as appropriate. The words ‘New Label’ have
been entered in the example below.
Button
A button is a control that performs an action when a user clicks it. When the button
is selected, Access runs what is called a macro which will execute the action that has
been set for that particular button. There are several actions that can be associated
with a button. Some of the commonly used actions include, add record, delete record,
find record and, open form.
To create a Button:
1. Open the Form, we will use the Registration Form created in Learning Activity 7.4
above.
6. The Command Button Wizard box will appear. Here, we need to select the action
that should occur when the button is pressed on the form. We want to create a
button which may be used to Add records to the Registration Table.
9. Select Next
10. We will now select a picture or text to be displayed on the button. For our example,
we will display text.
13. You can choose to name the button or use the default name provided by Access.
This is different from the name that will appear on the front of the button in the
form. In this example, we will name the button RegButton.
16. To see the button in action, you will need to return to Form View and then select
the button. Once the button is selected, you will get the option to enter a new
record in the Registration Table.
A combo box is useful where there are fields that have a set number of possible valid
responses. For example, you may choose to use a combo box to ensure that the user
enters ‘male’ or ‘female’ to represent gender or to ensure that the user only selects
items that already exist in the database.
We will now create a combo box on the Registration Form to replace the text box that
is now on the form and is bound to the Course Field from the Course Table. Once we
replace the text box with a combo box, the user will be able to select the appropriate
course from the drop down list that will be provided once the combo box is selected.
6. Select the desired location on the form where you would like to place the Combo
Box and click (using the left click) on the form.
7. The Combo Box Wizard box will appear. We need to determine where the combo
box will obtain its values from. Since we are replacing the Course text box that is
linked to the Course field in the Course Table, we will select that we want the
combo box to get its values from a table.
9. Click Next.
10. Select the table that should provide the values for the combo box. We will select
the Course Table.
12. Add both the CourseID and CourseName fields to the Selected Fields area.
16. Uncheck the Hide key column so that the CourseID field is shown.
18. Ensure that the CourseID field is highlighted as that is the field that has the values
we would like to store.
21. Select the CourseID field from the drop down menu.
23. You can choose to name the label or use the default name provided by Access. In
this example, we will name the button CourseID.
26. Since we create the Combo Box to replace an existing field, we should delete the
first field, called CourseID. Delete the one without the combo box.
27. Switch to Form view to test the Combo Box. Do this by clicking the drop-down
arrow and verify that the list contains the Course IDs. The combo box can now be
used to enter data.
If you want to include a drop-down list with a list of options that are not available in
a table or query but you will provide these values, then you will create a combo box
and choose the second option in the Combo Box Wizard, I will type the values that I
want. This will allow you to type the choices you want to appear in the drop-down
list. Each t=choice should be entered in its own row.
Use this video to explore and learn more about creating forms within an Access
database.
In Learning Activity 7.8 you will practice adding and editing records.
ACTIVITY 7.8
Creating a Combo Box (30 minutes)
Instructions:
1. Using the StuRegDB database, open the Course Form and create a
combo box on the form labelled Credits which provides the user with the
following choices:
●● 2 credits
●● 3 credits
●● 4 credits
2. Save your database and upload your database to the appropriate forum
in the Learning Exchange.
In this session you learnt how to add controls to a form. This helps to enhance the user
interface of the form.
UNIT 7 SUMMARY
In this unit, we examined forms in Access and how forms can be used to view, enter,
and edit data in the tables within a database. They may also be used to manipulate
queries. We also explored ways in which the form can be enhanced to improve the
user interface and to make it more user-friendly. The use of controls on forms was also
discussed including the use of subforms and command buttons to further enhance the
user experience when interacting with the form.