0% found this document useful (0 votes)
33 views8 pages

Forms and Subforms

The document provides instructions for creating and managing tables in Microsoft Access, specifically focusing on a Customer table, Product table, and Order table. It details the steps for defining fields, setting primary keys, and establishing relationships between tables. Additionally, it includes exercises for data entry and form creation to enhance database functionality.

Uploaded by

uttuffy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

Forms and Subforms

The document provides instructions for creating and managing tables in Microsoft Access, specifically focusing on a Customer table, Product table, and Order table. It details the steps for defining fields, setting primary keys, and establishing relationships between tables. Additionally, it includes exercises for data entry and form creation to enhance database functionality.

Uploaded by

uttuffy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

• 3 To create the first table (called Customer), locate ~ --::-:--:;-::-:-,----n::;::=;;::::-;;:;::::;---::---_

Field Nome Date Type Description (Optional)


the icons or labels that will allow you to Create a CID Short Text Customer's ID Number
Last Short Text Customer's last Name
Table and view its design. For now, the new table First Short Text Customer's First Name

is called Tablet.
Field Properties

Gtnoral Lookup I'


Fiold Slzo 4
Format 1v
lffiJ f Pnm.1~ '"Y ic r.°=1 1!'111 /!)~ut Mask
- .'.., Builder !)( B l.i_,Cl Caption customu·s ID number
Vi~ le-st Vahdat~ Rulr:-, PropMy Indexes Crute D1t.1 Rename/ Relationships D•fault Value
Sheol MIOOS. Delet• Maao • tvalidatlon Rule >999 The di splay ,.J:,'O 'Jl for lhe field. Select a r
Views
» ·~
Tools Show/Hide f'ltld. Rtt0rd a ~ EWnts
!Validation Text customer IDs start at 1000 for ma! or 'tr.t-: r a custom format Press ~t/efined
X Required No on formats. or help
.;
f;eld
::;:;7,: 1a lype
N •=me: - ,l~ 0a=- ;--:---,- - - - - =Descrip
----,--.-
tio.....,
n (-Op-,-
tion.....,
•1,--
) --- [Allow Zero Lenath Yes
Yes (Ouolicates OKl
0 Indexed
Unicode Comoression Yes I
IMEMode NO Control
IME Sentence Mode None -

:1/=i'-.. ,-.,
Field ProptrtJH
frext Aliqn General !
-
I ,?. : Help,

i
I=
·t1
:z Afield name can be up to 64 characters long,
including spaces. Press F1 for help on rield names.
Fig 8.9 Entering the design of the Customer table

Design view. F6 = Switch panes. Fl = Help--:- ---~- - -- -


Num lock - ~ ID 6 At this point, you should choose one field whose
Ag 8.8 Start with a blank table in Design view value uniquely identifies each record in a table.
If you do not define a primary key, Microsoft
4 Click in the first Field Name box and type 'CID', Access asks you if you would like to create one
then press Enter. In the Data Type column, when you save the table. For this exercise, make
choose the Text type, press Enter and then type the CID field the primary key, meaning that
the description as 'Customer ID'. Click below to every item has a four-digit number and no two
the Field Properties area to type 4 for the field are the same. To do this, select the CID field
size. Enter the following field names, types and and select the Primary Key icon , . Then click
descriptions in your table. the Save icon or Ctr! + S to save the table.
Field name Field type Description Name the table as Customer and click OK to
CID Text Customer ID Number close the dialogue box. You have created your
Last Text Customer's Last Name Customer table.
First Text Customer's First Name 7 Use the same Bookshop database. Locate the
icons or labels that will allow you to Create a
; Note that the CID field is Text, since Table and view its design.
calculations are not performed on this field, 8 Enter the following field names, types and
otherwise the Number data type would be descriptions in this table.
chosen. Click again on the CID :field name and
enter the following field properties: Field name Field type Description
Field Size: 4 PR-ID Text Product ID
Description Text Description of product
Validation Rule: >999
Cost Currency Unit cost of the product
Validation Text: Customer IDs start at 1000
9 Make PR- ID a primary key and save the table 12 Make CID and PR-ID the composite primary
as Product. key. Select the CID row, then while pressing
10 Use the same Bookshop database to create the Shift key, select the PR-ID row. Then click
another blank table in Design view. This will the Primary Key icon in the Menu bar. Both
be used to create the Order table. fields will have the Primary Key icon next to
11 Enter the following field names, types and them.
descriptions in this table. 13 Save the table as Order.
Field name Field type Description
CID Text Customer ID
PR-ID Text Product ID from inventory
QTY number Quantity ordered
DISCOUNT Yes/No 10% discount offered on
Product
Practical exercises using Microsoft Access
Exercise 3: Linking tables in the Bookshop database 6 You have created a relationship between the
1 Open the Bookshop database that was created Customer and Order tables.
in exercises 1 and 2. Locate the Database toolbar 7 Repeat the procedure in steps 4 to 6 to
,CJ . . create
relationship between P-ID m the Produ t a
that contains the Relationships icon Rela~ hlps •
c tab1e
and P-ID in the Order table.
2 Click on the Relationships icon, then click the
rm Exercise 4: Linking tables in other databases
Show Table icon ~:: on the toolbar to make it 1 Return to the previous example on the Sp
appear. Orts
database.

IT
3 Double-click on the Customer, Product and
2 Create the database called Sports, and then

M
Order tables. When you have finished adding the create the two tables.

O
tables, click Close.
3 Link the tables using a common primary key
4 N ow click on the. CID field in the Customer ,and
enter the data in each table.
table and drag it to the CID field in the
Order table.
5 An Edit Relationships window pops up
(Fig 8.12). Make sure the Enforce Referential
Integrity option is ticked in the checkbox and
press OK. This means that Access will help you
enforce rules so that your data is valid to start
with and remains valid throughout its use.

Edit Relationships ? X

Table/Query: I I
=v) I
Related Table/Query:
Create
jcust~~e!: ~: ~rder = I
loo
J
-cancel

'TIO Join Type .. I


0 Enforce Referential Integrity ICreate New.. \
DCascade Update Related Fields
D Cascade Delete Related Records
Relationship Type: One-T-o-Many

r;g 8.12 Enforcing rules on your data


Practical exercises using Microsoft Access
.
Exercise 5: Entering data • To modify a record if you have made an error,
select the record and field you want to update,
1 Open the Bookshop database that was created in
Exercise 1. and replace it with the text you want.
2 Double-click on the Customer table to open it. • To delete a record, right-click on the row and
3 To switch views between the datasheet and the select Delete Record (Fig 8 .16).
Design view, simply click the button in the top-
f 1i) Customer ' - - - - - - - -- - - - - - - x_j
left hand corner of the Access program window. CID Last First • Click to Add •

• Datasheet view /B : allows you to enter raw 1123-


~~;ew Record
,L~.___________
Rich
Todd ..___ __*]
data into your database table Lou

• Design view ~ - : allows you to enter fields,


1 Delete ,Record Ed
Bev
--- ~ Cui
data types and descriptions into your database Ann
ropy
table. ~D f'aste
4 Click on Datasheet view and enter the data
![ Bow Height...
shown below into the Customer table and save it. ' -

Record: H 12of-6 • Ill ':', No Filter Search


CID Last First --=-- - - - --- -------·
N umlock [@
1122 John Rich
1124 Aks Todd Fig 8.16 Deleting a record from the Customer table
1128 Tedd Lou
5 Click on the first record again and change the
• To add a new row, press Enter or select the CID to 112. Press Enter and you should see your
next line and enter the information. validation rules working (Fig 8.17).
::J Customer

/ 112
CID • Last First • IClick to Add .
.. John Rich
1124 Aks Todd
11 28 Tedd Lo u
1138 Yod
1 145 Ki ng
Microsoft Access X
116 7 Wa ll
1170 Cain )l Custo me r IDs start at 1000

* ( OK
I I .!::!elp

Num Lock

Rg 8.11 Entering a number that is not valid results in an error message

6 Select the Product table and double-click to open more complex forms. First, follow these steps to
it. create a basic form:
7 Enter the following records:
1 Open the Bookshop database with the Customer,
PR-ID Description Cost Product and Order tables. Each table should have
P3122 Pocket Diary $8.95 three records of data.
P3429 Jumbo Clips $4.15 2 Select the Customer table. Then in the menu or
P3430 Small Clips $2.75 ribbon, select the Create tab and then the Form

8 Select the Order table and double-click to open it. icon Form.
9 Enter the following records: 3 This option creates a simple form using all of the
fields in the table.
Customer ID Product ID QTY Discount
4 Use the form to enter the following records in the
1128 P3430 10
Customer table:
1128 P3639 500 y
1128 P3902 50 CID Last First
1138 Yod Ed
Exercise 6: Create a basic form 1145 King Bev

Microsoft Access does a very good job of creating a 1167 Wall Ann
1170 Cain Zed
form, and even provides a Form Wizard for creating
• Exercise 7: Create a form using the wizard
1 Select the Product table. Then activate the Form drop-down menu. To select the fields you want to
Wizard. In some versions of Access, there may be VIew on your form use the > arrow to move thern
an icon Ci Form Wizard , which can also be found in from the Available Fields window in the left
the More Forms option on the ribbon. pane to the Selected Fields window in the right
2 Select the fields needed for the form by selecting pane. You would use >> if you are selecting all of
a table or query from the Tables/Qyeries them (Fig 8.18).

Form Wizard

Which fields do you want on your form?

You can choose from more than one table or query.

Iables/Queries

/Table: Product
El
6vailable Fields: ,S.elected Fields:

Desrnpt1on Pf?-ID
Cost

Cancel 11 < gack I Next > 11 f inish I

Fig 8.18 Using the Form Wizard to select fields

3 Click Next.
4 Select the layout you wish and click Next. Exercise 8: Completing the data entry with the
5 You may be asked to select the style you desire. Use a Order ta ble
light background if you are going to print your form. 1 Use the Form Wizard or another method to
6 Click Next. enter the following data in the Order table:
7 Give your form the name Product and click Finish. Customer Product QTY Discount
8 You should see your form. ID ID
9 . Enter the following data using the form: 1138 P3745 100
1145 P3122 5
PR-ID Description Cost
1167 P3430 10
P3639 Round Labels $3.95
1167 P3639 100 Yes
P3745 Receipt Book $7.55

P3899 Highlighter $1.75

P3902 Black Pen $1.25


~,cerdse 9: Creating a form with a sub-form fill in those fields. Enter 25 for the quantity and
1 Select the Customer table. leave the discount blank.
14 Click the icon to add a new record. Enter the
2 Activate the Form Wizard.
following record of data for a new order:
3 Select the fields needed for the form by
selecting a table or query from the Tables/ CID: 1199
Qyeries drop-down menu. Use the> arrow to First: June
move the CID, then First and Last field names Last: J arway
from the Available Fields window in the left PR-ID: P3745
pane to the Selected Fields window in the QTY:25
right pane. Fo rm W izard

4 Practice adding additional fields from the tables


[
Which fields do you want on your form?

so that the fields are selected in the following You cz,n choose from more than one table or query.

order:
a Select the Order Table and add the CID and I ables/Querles

PR-ID fields (Fig 8.19a).


I .. . Iv
;,,
Fields:
Table : Product

-B
b Select the Product Table and add the ..,
Description and Cost fields.
c Select the Order Table again and add the
0
QTY and Discount fields. EJ
5 Click Next.
6 If prompted, view the data by Customer. You cancel 11 < ~ack [I Next > 11 f inish

will be able to see the form and sub-form in the


Fig 8. 19a Selecting the Order table
preview pane (Fig 8.19b).
Form W izard
7 Click Next.
8 Leave the layout option of the sub-form as How do you want to view your data?

Datasheet and click Next. b •~11~tu r 11er CD>, Frrst;, lllSt


9 Type Customer Form as the name of the main by Order
by Product

form and leave the name of the sub-form as


Order sub-form (Fig 8.19c).
10 Click Finish to see the final form (Fig 8.19d).
11 Locate record 3 to view the orders for the
customer Lou Tedd.
12 At the bottom of the form you will see Record: @Form w ith .:;ubform(s) O !.Inked forms
3 of 7.
13 Add the following order for Lou Tedd. Click Cancel II'--_< _.aa_c1c_ ..___
1
He>ct
_ >_____1I \ Bnlsh

in the PR-ID and enter P3745. The Customer Fig 8. 19b Viewing the data by Customer - you can see the form and
ID, description and cost of that product should sub-form in the preview pane
Fo rm Wizard

What tft!es do you went for your forms?

Form: lc§omerFonn-~ ~ ~ ~ ~ - -
Subform : [order Subfi>~-

Till!t's Ill the lnfomulllon the wlmrd needs to aellte your fonn.

Do you W!lf1t to open the form or modify the fonn's design?

@ Qpen thefonnto vil!W orenb!r ~ -

0 Mocfi'y the form's design.

a.nee! J _ <_ ~ _c1c_-1c_ _N_ext


LI _~_ _JJ I finish

rC:;~:e;Form
Fig 8.19c Naming the form and sub-form
X

CID

First

La st ~ edd

Order
Custom, • Product II • Description • Cost • QTY • J Discount .
_lms ffl30 Small ~ - $2.75 10
1128 P3639 Ro und Labels $3.95 500 0
1128 P3902 BlaclcPen $1.25 50

Record: H 111 -, of 3 • H >-' No Filter Seaich


1

Record: H li""ot 7

e::ig 8. 79d The nna/ form showing the orders for customer Lou Ted

You might also like