Access & Simple PDF
Access & Simple PDF
ca)
Last update: 24-Aug-1997
Next
Home
Previous
1 o f 15
Access Tutorial 6: Form Fundamentals
6.1 Introduction: Using forms as
the core of an application
Forms provide a user-oriented interface to the data
in a database application. They allow you, as a
developer, to specify in detail the appearance and
behavior of the data on screen and to exert a certain
amount of control over the users additions and mod-
ifications to the data.
Like queries, forms do not contain any data. Instead,
they provide a window through which tables and
queries can be viewed. The relationship between
tables, queries, and forms is shown in Figure 6.1.
In this tutorial, we are going to explore the basic ele-
ments of form creation using Access form design
tools. In subsequent tutorials, we will extend the
functionality and ease-of-use of our basic forms with
subforms (Tutorial 7), combo box controls
(Tutorial 8), and triggers (Tutorial 13).
6.2 Learning objectives
Do forms contain data?
How do I create a form?
FIGURE 6.1: The relationship between forms,
queries, and tables.
Courses Departments Employees
tables
queries
forms
Tutorial exercises 6. Form Fundamentals
Next
Home
Previous
2 o f 15
How do I make the contents of a field on a
form read-only?
What is an unbound text box? How do I create
one?
How do I create a form using the form wizard?
What is the difference between a columnar
(single-column) and tabular form?
6.3 Tutorial exercises
6.3.1 Creating a form from scratch
Although Access provides an excellent wizard for
creating simple forms, you will start by building a
form from scratch. This will give you a better appreci-
ation of what it is the wizard does and provide you
with the basic knowledge needed to customize and
refine the wizards output.
Create a new blank form based on the Courses
table, as shown in Figure 6.2.
The basic elements of the design screen are
shown in Figure 6.3. Use the View menu to dis-
play the toolbox and field list if they are not
already visible.
6.3.1.1 Adding bound text boxes
Add a bound text box for the DeptCode field by
dragging DeptCode from the field list to the form
background, as shown in Figure 6.4.
Reposition the DeptCode text box in the upper
left of the form.
Remember that you can always use the
undo feature to reverse mistakes. Select
Edit > Undo from the menu or simply press
Control-Z (this works the same in virtually all
Windows applications).
Tutorial exercises 6. Form Fundamentals
Next
Home
Previous
3 o f 15
FIGURE 6.2: Create a new form to display data from the Courses table.
Select the Forms tab from
the database window.
Access uses the fields caption property as the default label for the text box.
If no caption is specified, the field name (e.g., DeptCode) is used. To save
time editing labels, choose your captions with this feature in mind.
To move an object and its
label, drag the center of the
object (the cursor becomes
a white arrow). To move
just the object or just the
label, drag the upper left
handle (the cursor becomes
a pointing finger).
Tutorial exercises 6. Form Fundamentals
Next
Home
Previous
6 o f 15
Drag the remaining fields on to the form, as
shown in Figure 6.5 (do not worry about whether
the fields are lined up perfectly).
Select View > Form to see the resulting form.
Alternatively, press the form view icon ( ).
Select View > Form Design or press the design
view icon ( ) to return to design mode.
6.3.1.2 Using a fields properties to protect its
contents
Every object on an Access form (e.g., text box, label,
detail section, etc.) has a set of properties that can
be modified. In this section, you are going to use the
Locked and Enabled properties to control the users
ability to change the information in a field.
Select the DeptCode text box and right-click to
bring up its property sheet, as shown in
Figure 6.6.
Scroll down the property sheet to the Locked
property and set it to Yes, as shown in
Figure 6.7.
Switch to the form view and attempt to change
the contents of the DeptCode field.
A stronger form of protection than locking a field is
disabling it.
Return to design mode and make the following
changes: reset the Locked property to No; set the
Enabled property to No.
Attempt to change the contents of the DeptCode
field in form view, as shown in Figure 6.8.
Save the form as frmCourses.
6.3.1.3 Adding an unbound text box
All the text boxes created in the previous section
were bound text boxesthat is, they were bound to
a field in the underlying table or query. When you
change the value in a bound text box, you are mak-
Tutorial exercises 6. Form Fundamentals
Next
Home
Previous
7 o f 15
FIGURE 6.5: Add the text boxes and switch to form view to see the resulting form.
Add the remaining
fields to the form.
You can add more than one field to the form with one
drag-and-drop operation by holding down the Control
button when selecting the fields from the field list.
Select View > Form from the
main menu to view the form.