HIGHER ADMINISTRATION CREATING FORMS

advertisement
HIGHER
ADMINISTRATION
CREATING FORMS
IN MS ACCESS
South Lanarkshire Council
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
CONTENTS
INTRODUCTION
3
Using Forms
3
Creating a Form
3
GETTING STARTED
3
INSERTING A HEADER/FOOTER IN FORM
8
ENHANCING THE FORM
11
CHANGING FONT AND STYLE
13
INSERTING AN ADDITIONAL FIELD
13
INSERTING A NEW FIELD
15
INSERTING A NEW RECORD
16
USING A COMBO BOX
18
Using Limit to List
20
TAB ORDER
21
PRACTICAL EXERCISE 1
23
PRACTICAL EXERCISE 2
25
2
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
INTRODUCTION
To date we have inserted data into a database using tables. However sometimes it
becomes difficult to see the data relating to the whole record if there are too many
fields to fit on the screen at once. By not being able to see all the data at once we
often create errors when keying in or editing the data.
Using Forms
Forms can be used to present the data from the table in a way that is much clearer
and easier to understand. Within a form you can change the layout to suit your
requirements; you can edit/delete existing data as well as adding in additional data.
Creating a Form
There are 3 ways to create a form:
 Create your own from a blank design
 Use Autoform
 Form Wizard.
We will use the form wizard as the computer will ask questions and then set up the
form for us, this will allow us to edit the layout to suit our preferences.
GETTING STARTED
1 Open the file called HOLIDAY1 database.
Click on the
forms tab.
Double click on
create form by
using wizard.
3
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
The form wizard window will appear on your screen. You can change the table you
wish to extract the information from for your form, however, in this example we have
only one table in our database, HOLIDAY.
We now want to select the fields we want in our form by clicking on the arrow icon.
In this example we want: CUSTOMER ID, CUSTOMER NAME, RESORT AND
ACCOMMODATION fields.
>
NOTE:
If you wanted all the fields in your form, by clicking on the double arrow they would
all go over into the selected fields area.
Similarly if you move a field over in error click on the
the available field box.
<
arrow and it will return to
Check the correct
table is selected for
your form.
Click on the
arrow to move
the fields across.
Check that your screen is the same as the one shown below.
Click on Next.
4
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
3 The next window is giving you the chance to decide the layout for your form.
There are 4 layouts that we will use for our forms and these are shown below:
COLUMNAR
TABULAR
Displays many
records on the
screen at once
and is similar to
datasheet view.
DATASHEET VIEW
JUSTIFIED
Like the columnar
layout it only
displays one
record at a time
on screen.
COLUMNAR
Displays only one
record at a time
and is the most
popular layout.
TABULAR
DATASHEET VIEW
The same as entering
the information in
the table option.
JUSTIFIED
5
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
Select columnar
layout.
Click Next.
4 Now you have to decide the style for the form, again there are various choices.
As you click through the different styles you will see a preview of each one.
Select Blends.
Click Next.
5 You will now be asked to give your form a title.
Key in HOLIDAYS IN
SPAIN as your title.
Click Finish to view
your form.
6
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
6 Your form should be the same as the one shown below.
Click here to move through
your records on screen.
By using the wizard you have created a very simple form. We will go on to learn how
to edit the form as well as inserting your name into it using headers and footers
which will mean when you print the form you can obtain your own printout.
7
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
INSERTING A HEADER/FOOTER IN THE FORM
You can insert a page header/footer which means that it would print on every page
of your form, however, it is not visible on screen unless you go into print preview.You
can insert a form header/footer which will only be printed on the first page of the form
and the form footer will be printed on the last page of the form but these are visible
on screen with every record.
For this example you will insert your name in a form footer using the following
instructions.
1 Open the form Holidays in Spain.
2 Click on the design icon
at the left hand corner of the screen.
3 The screen will change to the design view of the form as shown below:
Click and drag the
arrow downwards to
create room to insert
a header.
There is no room to insert the form header or footer on the design view screen at
present. To create room you place the pointer on the grey line between the words
Form Header and Detail and it will change to an arrow,
click and drag the
arrow down to create room for a header as shown above.
4 Your screen should now be the same as below:
You have now created
room to insert a form
header.
8
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
5 In design view the toolbar should be shown on your screen automatically, if it is
not go to the View menu and drag down to Toolbox.
Click on the label icon and
then click into the form
header space once, now key
in your header.
In this example key in
Majorcan Holidays.
6 Your form header should now look like this:
7 Using the same steps as above insert a form footer - Biggar Travel Agent.
8 Now click to view the form using the View icon
shown below:
It should be the same as
Form Header.
Form Footer.
9
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
9 Return to the design view of the form by clicking on the Design icon.
10 Go to the View menu and select Page Header/Footer as shown below:
Move your
pointer to View
menu
Select page
header/footer.
Your screen
will appear
like this:
11 Key in the following page header and footer using the same method as above.
Key in:
REF: 123/Own Initials
as the Page Header.
Key in:
Own Name
as the Page Footer.
12 View your form and print one copy of it.
10
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
ENHANCING THE FORM
If you look closely at the Holidays in Spain form we have created, some of the
information is truncated on your screen. We are now going to adjust the form so that
all data is visible.
We cannot see all the data in
these fields/labels.
1 Firstly you need to extend the form’s width by going up to the top of the form until
your pointer changes to
and drag the pointer to the right until you get to 10
on the ruler.
2 Click onto the field Customer ID i.e. the box with the yellow border around it and
move the pointer to the top left hand corner of the field box until the pointer
changes to symbol. (Ensure the pointer is not a full hand as this will move the
field and label together). Now drag the field to the right hand side of the form.
Do the same with the other 3 fields.
3 To increase the size of the field click on the field box and move the pointer to the
right hand side and drag to the appropriate size. Do the same with the other fields
as well as any labels that need increased in size.
4 The detail section of your form should appear as shown below:
11
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
5 Although all the data is visible we can still further enhance the presentation of the
form. Click on the field Customer ID and hold your shift key down as you click on
the remaining fields. Move your pointer to the Format menu and drag down to
align then select right as shown below:
Go to the Format menu.
Select Align then
Right.
6 The computer will automatically align your fields with the field that is the furthest
right. Click to align the text to the right by clicking on the right justify icon on the
toolbar.
7 Now using the same method as above align all the labels to the left.
12
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
CHANGING FONT AND STYLE
In the form we can change the font style, size and colour as well as adding borders
and fill colours to text boxes.
You can either change each label and field box individually or if you want them to
change to the same font we can select all labels at once and then change the font,
style etc.
1 Open the Holidays in Spain form in design view.
2 Click on the form header label, hold your shift key and click on page header label,
page footer label and form footer label.
3 On the formatting toolbar change the font to Comic Sans and size 16. Click on
the font colour icon
and select pink.
4 Click anywhere in the form to deselect the labels. Adjust the size of the label
boxes if required so that all data is visible.
5 Select the labels in the detail section of the form using the same method as
above.
6 On the formatting toolbar click on the line/border colour icon
red. Adjust the boxes so that all data is visible.
and select
7 Save the form and close it down.
You could also choose to insert a backfill colour into one of the textboxes by
selecting the textbox and clicking on the icon
and choosing the fill colour.
The same applies to choosing a special effect for the textbox, select the textbox you
want to apply the special effect to then click on the icon
and choose the
special effect i.e. raised.
INSERTING AN ADDITIONAL FIELD
When we first created the Holidays In Spain form we used only 4 of the 6 fields in
our design however we can go back and insert additional information from the table
into our form.
1 Open up the Holidays in Spain form in design view.
2 Increase the detail section of the form to allow you to insert additional
information.
3 Click on the textbox icon
on the toolbar and draw a textbox in the detail
section of the form. The text will be hidden by the unbound box. Separate the
label and the text box by clicking on the unbound box and moving to the left hand
13
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
corner of the box until the pointer changes to a pointed finger and drag so both
are positioned appropriately on the form.
It should look like this:
At the moment the label and field are unbound because the computer doesn't know
that there is a link between the label/field and an existing table already created in the
database. We need to change the properties of the label/field to link it with the table
so the data can be extracted automatically and inserted into the form.
4 Click on the label i.e. in the example above Text 12, right click and select
Properties. The following property sheet will appear:
Click on the format tab.
Delete the text
beside the heading
Caption. Key in
TYPE OF BOARD.
Your properties box should
appear like this.
Close to accept your
adjustment.
5 Now click on the field and right click and select Properties.
14
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
6 Click on the Data tab and in the Control Source box select Board as shown
below:
Click on Data tab.
In control source select the
field you want to use i.e.
Board.
7 Click close on the menu bar to accept the adjustment.
8 Adjust the label and field alignment, size and insert a border around the label to
match the rest of the detail section.
9 Click on the form view icon and all the data relating to board will be visible on the
form.
10 Save and close down the form.
INSERTING A NEW FIELD
If you are using the form and decide that you would like to create a new field, for
example, with the Holidays in Spain form, we might want to insert a field called
Method of Travel. This field was not in the original table that we used to design our
form from and therefore must be inserted into the table before we can insert it into
our form.
1 Click on the tables tab and select HOLIDAYS.
2 Click on the design icon.
3 Insert a new field called METHOD OF TRAVEL. This is a text field.
4 Close the design view down and save the table.
5 Open up the form HOLIDAYS IN SPAIN in design view and using the same steps
as above insert a text box in the detail section of the form.
6 Click on the label and right click on properties, under the format menu against
Caption, key in TRANSPORT. Click close to accept the adjustment.
7 Click on the field and right click on properties, under the data menu against
control source, scroll down and find Method of Travel. Click close to accept this
adjustment.
15
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
8 Adjust the fields and labels so all data is visible and they are aligned with all other
fields in the form. Remember and change the line colour on the label to red.
9 Click to view the form and you will notice that the new field has been inserted but
it doesn't have any data against it. Insert the following information while in form
view:
CUSTOMER NAME
Mr & Mrs Perry
Mr & Mrs Mitchell
Mr & Mrs Lamb
Mr & Mrs Dunbar
Mr & Mrs Thomson
Mr & Mrs Gibson
Mr & Mrs Samson
Mr Gardiner
Miss Drife
Mr & Mrs Black
Miss Frame
Mr & Mrs Hunter
METHOD OF TRAVEL
Air
Car/Ferry
Air
Car/Ferry
Car/Ferry
Car/Eurotunnel
Air
Coach
Coach
Car/Eurotunnel
Air
Car/Ferry
10 Save your form and go back to the tables and open up the HOLIDAYS table.
The data you have inserted into the form has also been inserted into the table as the
computer understood that both were linked. This is because we have used BOUND
fields which means that they are tied to a table or query within the database. As long
as we use bound fields the computer will automatically update the table with any
amendments we make to the database within the form window.
The main reason for inserting the additional data in the form rather than the table is
that it is much easier to see where to insert it and fewer errors will be made as you
only have one record on the screen at a time.
INSERTING A NEW RECORD
We can insert a completely new record while in form view.
1 Click on the icon at the bottom of the form as shown below:
16
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
2 Now insert the following information into the form:
Customer ID
Customer Name
Resort
Name of
Accommodation
Type of Board
Transport
113
Mr Hope
Maguluf
Hotel Tropicana
HB
Air
3 Save the form and print one copy of it before closing down.
4 If you want you can check that the additional record has been inserted in the
table HOLIDAY.
17
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
USING A COMBO BOX
We can use combo boxes in our forms the same way as we use them when creating
forms in Word. A combo box provides a list of options for the user to select one from
which can save time for the user of the form. We are going to change one of the
existing fields in our form to a combo box and use a bound field which means that
any changes we make within the form window will also be changed in the database.
1 Open up the Holidays in Spain form in design view.
2 Click on the field Board and right click.
Select Change To.
Select Combo Box.
Your field should now look the same as shown below:
We now need to insert the information for the form user to choose from.
3 Click on the field board and right click to select Properties. The following menu
box will appear on screen:
Ensure the data tab is
selected.
18
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
Row Source Type is where we have to insert the data that will be included in our
drop-down list. There are 3 types of source data as shown below:
Table/Query - select when each entry in the field will be different.
Value List - select when there are several entries to be the same.
Field List - select when the entry is to be field names from a specific
table or query.
For the field that we are changing to a combo box there are only 2 options either SC
or HB and therefore there are many entries the same. For this example we need to
select Value List.
Click on Row Source Type
and select Value List.
In Row Source type exactly the
following with NO SPACES;
"SC";"HB";
Then close the box.
NOTE
When specifying values inverted commas must be around each one and separated
by a semi-colon with no spaces. If you find it hard to see what you are keying in here
click into the row source box and then hold your shift key and press F2. This will
zoom this box to make it easier to see what you are keying in.
19
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
4 Make the following changes to the form.
CUSTOMER NAME
Mr & Mrs Perry
Mr & Mrs Lamb
Mr & Mrs Thomson
Mr & Mrs Black
Mr Hope
BOARD
HB
SC
SC
SC
SC
5 Save the form and print one copy of it.
Using Limit to List
Although we have set up a combo box for the field Board there is nothing to stop the
user of the form keying in a different response from the options available in the list.
We can change the properties of the combo box field to only allow the user to select
an entry from the list given.
1 Click on the field board, right click and select Properties.
2 The following Properties menu will appear:
Click on the data tab.
Click on the arrow
against Limit to List and
change to Yes.
3 Close down the Properties menu.
4 Click on form view, change Mr & Mrs Perry to FB in the Board field. Click off the
field and a pop up box should appear informing you that your entry is not included
in the list available. You will not be able to move from this until you change the
entry to either SC or HB from the list. Change it back to SC. and close the form
saving the changes.
20
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
TAB ORDER
If we were to tab through the fields at present they would be in the columnar layout
that we started with. Sometimes we may change the position of the label and fields
or we may want the order to match a manual form that you have issued and are now
inputting responses to. Therefore we can change the order we move through the
fields, to suit our layout.
1 Open the Holidays in Spain Form in design view.
2 Go to the view menu and select tab order as shown below:
3 The following box will appear:
The 2 new fields inserted after we
used the wizard have shown up
without the label names. Click
cancel on this box and we will go
back and adjust this.
21
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
4
In design view click on the Board field and right click to select Properties.
Select the All Tab.
Against Name key in
the Label Name i.e.
Board then click close.
5
Click on the field Method of Transport and follow the same steps as above, only
this time insert the name as Method of Travel.
6
Now go back to the view menu and select tab order. You tab menu should look
the same as the one shown below:
Select the detail
section as this is what
we want to change.
We are going to create our own order by clicking and dragging the field to the new
position.
Change to the order to as shown:
Click OK.
Change to form view and check whether the tab order you have set works. Close the
form and save the changes.
22
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
PRACTICAL EXERCISE 1
1 Open up the database Equipment.
2 Create a form using the wizard which includes the following fields:
Instructor Responsible
Supplier Name
Supplier Contact
Supplier Tel No
Equipment
Price per Item.
3 Use a justified layout and sandstone style.
4 Name the form Equipment Details.
5 Insert a form header - Equipment 2004. (Remember to increase the section to
allow you space to key in the header.)
6 Insert a form footer - Hamilton Branch.
7 Insert a Page Header - Extracted from Equipment Database. (View, Page Header
and Footer.)
8 Insert a Page Footer - Own Name.
9 Change the form header and footer to Britannic Bold font, size 18, bold and red.
Move the labels to the right hand side of the form and then align them to the right
and fill with pale blue.
10 Change the page header and footer to Times New Roman font, size 16, italics
and blue.
11 Adjust the size of the page header and footer label box so that the text appears
on one line.
12 Move the Page Header and footer to the left of the form and then align them to
the left.
13 Change the labels in the detail section to Arial font, size 11, bold and pink.
14 Change the fields to Comic Sans font, size 10 and green.
23
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
15 Adjust the layout of the detail section to be the same as below:
Remember - when the pointer changes to a hand it will move the label box and the
field but when it is just a finger it will only move the item you are clicked on and
dragging.
16 Adjust the label and field boxes so that all data is visible remember and check in
form view as well.
17 Change the tab order to be instructor responsible, equipment, price per item,
supplier name, supplier contact and supplier telephone number.
18 Save the form and print one copy of it.
24
Administration
Higher
Creating Forms in MS Access
-------------------------------------------------------------------------------------------------------------------------
PRACTICAL EXERCISE 2
1 Open up the database Equipment.
2 Create a form using the following fields:
Instructor Responsible
Equipment
Quantity
Date Purchased
Price per Item
3 Use the Columnar Layout and Expedition style.
4 Insert a Form Header - Inventory of Equipment and a Form Footer of April 2004.
5 Insert a Page Header of your name and a Page Footer of your class.
6 Enhance the form using different fonts, styles and sizes. Change the layout of the
detail section to equipment and date purchased on the same line.
7 Insert a new field called Replacement Price and key in the following information:
Canoes
Life Jackets
Paddles
Helmets
Quad Bikes
Waterproof Jackets
Waterproof Trousers
£475.00
£105.95
£50.00
£19.95
£3,500.00
£70.50
£42.00
Ropes
Harnesses
Targets and Stands
Bows
Arrows
Armguards
£75.75
£200.00
£255.50
£125.00
£20.90
£17.75
8 The field for Replacement Price should be on the same line as Price per Item.
9 Change the tab order so that it moves through your form in a sensible way.
10 Add the following new record to the form:
Instructor Responsible
Equipment
Quantity
Date Purchased
Price per Item
Replacement Price
Tommy
Mountain Bikes
10
26/3/2004
£110
£125
11 Save the form and print one copy of it.
25
Download