0% found this document useful (0 votes)
42 views35 pages

Access 2010: Building Access Databases: Practical Workbook

Uploaded by

Naruto 74 Henry
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)
42 views35 pages

Access 2010: Building Access Databases: Practical Workbook

Uploaded by

Naruto 74 Henry
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/ 35

Access 2010:

Building Access
databases
Practical workbook

Aims and Learning Objectives


This course provides participants with the basic skills necessary to develop a simple Access
2010 database from a paper-based design.
The core learning objectives for this course are to:
 gain a simple overview of the core relational database concepts
 build a simple database from a paper-based design – to achieve this candidates will:
o create tables and set relationships between tables
o import pre-existing data and enter data manually
o use the wizard to create and use data entry forms to simplify data input
o base a form on a parameter query to view filtered data (if time allows)
o add automation to a form using buttons and macros (if time allows)

Note on versions of Access:


o Access 2013 users: should have little problem using this document.
o Access 2007 users: should have few problems using this document if they keep in mind
that the 2007 Office button has been replaced by a File tab in 2010 and that various
command icons have moved, mostly to new locations within the same Ribbon tab.
o Access 2003 users: this document will be of little or no use.

University of Bristol IT Services document acc-39


Access 2010: Building Access databases (acc-39)

Document information
Course files
This document and any associated practice files (if needed) are available on the web. To find
these, go to http://www.bristol.ac.uk/it-services/learning/resources and in the Keyword box, type
the document name.

Related documentation
Other related documents are available from the web at:
http://www.bristol.ac.uk/it-services/learning/resources

This document is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.0 UK:
England & Wales Licence (http://creativecommons.org/licences/by-nc-sa/2.0/uk/). Its “original author” is the
University of Bristol which should be acknowledged as such in any derivative work.

Access 2010: Building Access databases (December 2013)


© 2013 University of Bristol.
Access 2010: Building Access databases (acc-39)

Contents
Document information
Task 1 Course objectives .................................................................................. 1
Task 2 Introduction to relational database concepts....................................... 2
Task 3 Create a new database file ..................................................................... 4
Task 4 Create a table manually ......................................................................... 5
Task 5 Create new tables automatically ........................................................... 6
Task 6 Fine–tune the Student and Subject tables............................................ 8
Task 7 Create relationships using two methods ............................................ 10
Task 8 Create a dropdown list not based on a relationship .......................... 14
Task 9 Create a form and subform using Form Wizard ................................. 15
Task 10 Customise your form – basics ............................................................ 17
Task 11 Customise your form using the Property Sheet ................................. 22
Task 12 Add a calculation to a form.................................................................. 26
Task 13 Introducing automation ....................................................................... 27
Task 14 Create a form that asks you what data you want to see .................... 29
Appendix A Setting a tabbed display ...................................................................... 31
Access 2010: Building Access databases (acc-39)

Important: security information


Data used on this course is fictitious. Remember that if you store or otherwise process
personal or restricted University data on a database, you should be aware of your
responsibilities toward keeping this data safe and secure, both from point of view of
University regulations and the Data Protection Act.
See the Information security website (www.bristol.ac.uk/infosec) for further
information.

Important: prerequisites
Before attending this course you must have attended "Access 2010: An introduction",
or otherwise have experience of using Access.
Without this prior experience it is likely that you will not benefit from attending
this course and will struggle to keep up with the brusque pace at which the
course is run.
Access 2010: Building Access databases (acc-39)

Task 1 Course objectives


Objectives To provide a ‘road map’ for the course.
Comments Generally speaking, the table creation tasks are covered during the morning and the
data entry form creation tasks are covered during the afternoon.

What you should already know


Reminder of concepts introduced on the ‘Access 2010: An introduction’ course:
1. Tables hold the data and all other objects do something to or with this data,
therefore, logically, tables must be built before other objects.
2. Tables are not the best environment for entering, modifying or deleting data,
which is why we build data entry forms – to make data management easier.

Before we get started with development


We are going to:
1. Gain a basic overview of core relational design issues.
2. Discuss table design and introduce examples of good practice.

Table creation
We are going to (though not quite in this order):
1. Build a table and enter data manually.
2. Import pre-existing data from Excel and automatically create new tables.
3. Modify the above tables to ensure correct data types, field sizes and/or formats.
4. Import a table along with data from another Access database.
5. Add the required relationships and create dropdown lists.

Data entry form creation


We are going to:
1. Create a form and subform to let data be input into two tables at the same time.
2. Modify the form's appearance and modify the way we can interact with it.
3. Add a new field to the form to automatically calculate student age.
4. Create a form that asks you which data you want to view. (If we have time.)
5. Add buttons to make navigating between records easier. (If we have time.)

1
Access 2010: Building Access databases (acc-39)

Task 2 Introduction to relational database concepts


Objectives To gain a basic overview of: how relational databases are designed; what the
relationships between tables mean; where ‘primary’ and ‘foreign’ keys must be
located for a design to be successfully built using Access.
Comments Relational database theory is a major topic, but the good news is that you don’t
need to understand relational theory to build working databases. There are some
rules to follow and these rules work whatever the size or complexity of the database.

What is a relational database?


A relational database is made up of a set of tables, which are linked together by
relationships. Each table holds data about one ‘thing’. For example, the simple
student database we will build has separate tables for the following:
o Student data
o The degree subjects that students can take
o The faculties to which students can belong
o The marks awarded to students
The reason for having separate tables is to prevent duplication and to make sure
that data is uniformly held. As soon as you duplicate data, problems occur:
o You increase the risk of typing errors and of entering data in inconsistent ways
o You cannot be sure that search or sort results are accurate
By using separate tables for each distinct thing, you enter the data once and if you
need to add it data again, you select it from a list. This prevents the above problems.

What does a simple relational database design look like?


This is the database we will build. The diagram below is called a Logical Data
Structure (LDS) – also known as an Entity-Relationship (ER) diagram.

Figure 1 – LDS for four table database with three one-to-many relationships (the
number of tables and the relationships between them will differ from database to
database)

2
Access 2010: Building Access databases (acc-39)

What do the relationships mean?


Relational databases are built up of tables related to each other in ‘one-to-many’
relationships, in that one of something relates to many of the other thing. The
relationships above mean (it helps to read both ways):
o One faculty includes many students or many students belong to one faculty
o One subject is taken by many students or many students take one subject
o One student is given many marks or many marks are given to one student

How are the tables linked?


The tables are linked by key fields – you don’t have to understand the concepts but
if you follow some basic rules you can design and build working databases:
1. Every table must include a primary key – this key must uniquely identify each
individual record in its table. Student number would make a good primary
key in the student table, because no two students will ever have the same
student number.
2. Where a table is linked to another table, the primary key from the table at the
‘one’ end of the relationship must be added to the table at the ‘many’ end of
the relationship, where it is known as a foreign key.
3. That’s it – just two rules to follow to work out where keys go!

Figure 2 – LDS showing the primary and foreign keys for each table

The $60,000 question is, how do you know which tables and fields you need in your
database in the first place? Unfortunately, this is outside the scope of a beginners’
course.
There are methods you can use to help you come up with a workable design – see
the MS Access database design checklist at:
 http://www.bristol.ac.uk/it-services/applications/databases/access/checklist/.

3
Access 2010: Building Access databases (acc-39)

Task 3 Create a new database file


Objectives To create a new database file and look around the Access work environment.
Comments If you close the database file at any point you will be presented with a security
message on reopening. If so, click the yellow Enable Content button.

3.1 To open Access 2010 and create a new Access database file:
 Click on the Start button and start to type Access into the Search programs and
files box. When Access 2010 appears in the list of matches, click on it once to open
the application.
 On the right-hand side of the window enter Student in the File Name field.
 Click on the browse icon (the open folder logo) to the right of the File Name field
and select where you want to save the new file (if in the training room, this will be
your O Drive, so that you can access your training files from other locations) then
click OK.
 Check that the file path underneath the File Name field is correct and click Create.
3.2 To look around the Access work environment:
 Close the table that has automatically opened by right-clicking on the tab saying
Table1 and selecting Close, then look at the Access environment.
Note If you do not see a tab, then you will need to set tabs for open objects. See the
appendix to set tabbed display.

Figure 3 – the Access workspace

Item What is it?


File tab Includes file save and general database options
Ribbon Includes most menu options (right-click on objects for other options)
Navigation Pane Open objects from here (once you have built them)
Main workspace This is where you build new objects or work with existing objects

4
Access 2010: Building Access databases (acc-39)

Task 4 Create a table manually


Objectives To create a table to hold student marks in Design View, add the relevant
relationships and enter some data to test the new table.
Comments We can’t yet add any data because we don’t know what the student IDs are going to
be until we’ve created the Student table and added an AutoNumber for IDs.

In your own time…


There are various words that must not be used as field or table names because Access uses these
words as commands – these are called reserved words. Use Google to find a list of reserved words
for your version of Access. Are you surprised at some of the words that you mustn’t use? Which ones?

The basic building blocks for building any Access table are:

Building block Notes


1. Give each data entry field o Give each field a sensible name. You mustn’t use symbols
a name (except the underscore), gaps or reserved words.
2. Choose a relevant data o Rule of thumb – only make it a numeric field if you intend to
type for each field do calculations with it.
3. Fine tune the Field Size or o The most important properties are covered in this course.
Format properties
4. Enter a caption o This is not strictly necessary, but lets you ‘override’ a non-
friendly field name with a more user-friendly name (you can
use reserved words a captions).
5. Assign the primary key o Every table MUST have a primary key that uniquely
identifies every individual record in a table.
6. Save the table o Give it a sensible name – again, no reserved words, gaps
or symbols.

4.1 To create the new table:


 Click on the Create tab in the Ribbon and select Table Design.
 Enter the data in the table below as relevant into Field Name, Data Type and Field
Properties (Field Size, Format and Caption as indicated).
Field Name Data Type Field Size/Format Caption
MarkID AutoNumber Field Size: Long Integer Mark code
StudentNumber Number Field Size: Long Integer Student ID
SubmitDate Date/Time Format: Long Date Submission date
Title Text Field Size: 30
Type Text Field Size:10
Mark Number Field Size: Integer
Comment Text Field Size: 50 Comments

 When done, select MarkID and click on the Primary Key icon in the Ribbon.
 Click the Save icon, name the table Mark then close the table.
Note In reality, we would now build the rest of the tables, create the relationships and add
test data to make sure that the database works in the way we expect. However, time
constraints on the course prevent us doing this … so we are going to 'cheat' – but
the 'cheats' in the following task provide useful learning points in that if you have
pre-existing data there are ways to prevent you having to type it all over again.

5
Access 2010: Building Access databases (acc-39)

Task 5 Create new tables automatically


Objectives To create new tables from student and subject data held in Excel spread sheets and
to import a pre-existing table with faculty data from another Access database.
Comments You need to ‘cleanse’ Excel data before importing it into Access, such as removing
empty rows or cells with explanatory text and so on so that only column headings
and data exist. You can assign data types within the Import Wizard, but it is easier to
instead modify the new tables from within Access – which we will do later.

5.1 To create the Student table by importing pre-existing Excel data:


Note If in the training room, you will be shown where the files for this and the following
tasks are located. If doing this as a self-paced session, the file is amongst the
zipped practice files available from the IT Training website – see the back of the
cover for information on location of practice files.
 In Excel, open Student.xlsx and notice that the column headers are Access-
friendly with no gaps, reserved words nor symbols.
 Make sure that you now close Excel or the import will fail.
 Back in Access, select the External Data tab from the Ribbon.

Figure 4 – choose Excel from Import & Link

 In the Import & Link section select Excel.


 Browse to Student.xlsx, select the file and click on Open.
 Make sure that Import the source data into a new table in the current database
is selected and click OK.

Figure 5 – it is very important that you tick this box

 Click Next and tick First Row Contains Column Headings, if not already ticked,
then click Next.
 Click Next again and select Let Access add primary key.

6
Access 2010: Building Access databases (acc-39)

 Click Next, call the new table Student, then click Finish, followed by Close.
 Open the Student table to view the data – if you see ###### just make the column
wider to see the data – then close the Student table.
5.2 To create the Subject table by importing pre-existing Excel data:
 Do exactly the same as above with the following differences:
 Use the file, Subject.xlsx.
 When you get to the relevant point, select Choose my own primary key
and choose Subject from the dropdown.
 Name the new table as Subject.
5.3 To import a table, complete with data, from another Access database:

Figure 6 – select Access

 Select the External Data tab from the Ribbon and in the Import & Link section
select Access.
 Browse to Faculty.accdb, select the file and click on Open.
 Make sure that Import tables, queries, forms, reports, macros, and modules
into the current database is selected and click OK.

Figure 7 – select Faculty from under the Tables tab

 In the Table tab, select Faculty and click OK, followed by Close.
 Open the Faculty table, look at the data and then close the table.

7
Access 2010: Building Access databases (acc-39)

Task 6 Fine–tune the Student and Subject tables


Objectives To add correct data types and field sizes/formats for the new Student table.
Comments Some of this could be done whilst importing the data from Excel, but the Import
Wizard is limited. Doing this in Design View means that you can ‘fine-tune’ and do
other useful things, such as adding captions to make up for unfriendly field names.

6.1 To modify data types, field sizes and/or formats in the Student table:
 Make sure that all other objects are closed then right-click on the Student table in
the Navigation Pane and select Design View.

Figure 8 - these are the only parts that you need be bothered with

 For each Field Name, update the Data Type and Field Properties (Field Size,
Format and Caption) as shown in the table below.
Field Name Data Type Field Size/Format Caption
Faculty Text Field Size: 3
Subject Text Field Size: 10
YearNumber Number Field Size: Integer Year
PaidFees Yes/No Format: True/False Fees paid?
FirstName Text Field Size: 30 First name
LastName Text Field Size: 40 Last name
Title Text Field Size: 10
Gender Text Field Size: 15
DateOfBirth Date/Time Format: Long Date Date of birth
Address1 Text Field Size: 50 Address line 1
Address2 Text Field Size: 50 Address line 2
Address3 Text Field Size: 50 Address line 3
Town Text Field Size: 50
Country Text Field Size: 20
Postcode Text Field Size: 15

8
Access 2010: Building Access databases (acc-39)

 In PaidFees, click on the Lookup tab in the Field Properties and change Text Box
to Check Box (this may already be the default, in which case don’t worry).
 Rename the ID field to as StudentNumber and give it the caption, Student ID.
 Select Datasheet View from the Views section of the Ribbon (save when prompted
– and say Yes to the following warning message) and look at your modified table.

Question: where do the field names shown at the top of each column come from?

6.2 To modify data types, field sizes and/or formats in the Subject table:
 Close the Student table then open the Subject table in Design View.
 Update the fields as per below then close and save the table.
Field Name Data Type Field Size/Format Caption
Subject Text Field Size: 10 Subject code
CourseName Text Field Size: 50 Course name

9
Access 2010: Building Access databases (acc-39)

Task 7 Create relationships using two methods


Objectives To link the tables with the relationships as identified on the paper-based design; to
fine-tune, then check and test the relationships.
Comments Using the Lookup Wizard to build relationships between foreign and primary keys
lets us easily do some useful things that are otherwise fiddly and time-consuming,
but you always need then fine-tune the relationships. We will create the final
relationship in the ‘traditional’ way just to show how it’s done.

Important rules:
 The data type for primary and foreign key must always match.
 If a primary key is an AutoNumber, the foreign key end must be set as Number, Long
Integer – this is because the AutoNumber data type is number, long integer.
 Foreign key fields MUST only contain values already contained in the related primary
key otherwise Access will not let you create a relationship.

7.1 To compare the values held in the primary and foreign key fields in three tables:
 Open the Student, Subject and Faculty tables and use the tabbed display to view
one table after the other.
 Notice that the values in the Subject field in the Subject table are repeated in the
Subject field in the Student table. Similarly, notice that the values in the Faculty
code field in the Faculty table are repeated in Faculty in the Student table.
Note Look back at the database design in Task 2 and you will see that the Subject and
Faculty fields in the Subject table are the foreign keys for the Subject and Faculty
tables respectively – you can guess that the cleansing work done in Excel was very
fiddly so as to get this right.
7.2 To create the first relationship using the Lookup Wizard:
 Close all the tables except the Student table and open this in Design View.
 Click in the Data Type cell for the Faculty field and select Lookup Wizard from the
dropdown list.
 When the Wizard starts, leave the first screen as the default and click on Next.
 Select Table: Faculty and select Next.
 Double-click on Faculty and FacultyName in turn to move them across to the
Selected Fields section and click Next.
 Sort by FacultyName ascending (don’t select Faculty by mistake) and click on Next,
followed by Next again.

Figure 9 – make sure you tick just this one option


10
Access 2010: Building Access databases (acc-39)

 Tick the box next to Enable Data Integrity and click on Finish – say Yes to the next
two messages.
7.3 To create the second relationship using the Lookup Wizard:
 Do exactly the same as above but for the Subject field and with the following
exceptions as you go through the Wizard:
 Select Table: Subject as the linking table.
 Take across both Subject and CourseName to the Selected Fields section
 Sort ascending by CourseName.

Note: any forms created will have dropdowns (which are sorted alphabetically) created automatically
because forms inherit the properties from the table as at the point of creation.

7.4 To fine tune the new relationships so that they work properly:

Figure 10 – select Relationships from the Database Tools tab

 Close the Student table (and any other tables you might have open), click on the
Database Tools tab and click on Relationships.

Figure 11 – select this to open the Edit Relationships window

 Right-click on the relationship between the Faculty and Student tables and select
Edit Relationship (this is fiddly and you might need to try several times before you
get the correct right-click menu).

11
Access 2010: Building Access databases (acc-39)

Figure 12 – only the top two boxes should now be ticked

 In the Edit Relationships window, tick Cascade Update Related Fields and click
on OK.
 Do exactly the same for the relationship between Student and Subject.
 Close the Relationships Window saving when prompted.
7.5 To check the two relationships and the dropdowns:
 Open the Student table in Datasheet View and notice that now, instead of seeing
the codes in the Faculty and Subject fields, you can see the names.
Note In the background, the codes are still being entered into these fields; it’s just that
Access is now showing us something more user-friendly.
 Click in these and notice that both now have a dropdown.
7.6 To add in the relationship between the Student and Mark tables:
 Close the Student table and open the Relationships Window again.
 Click on the Show Table icon in the Ribbon, add the Mark table and click
on Close.
 Click on StudentNumber in the Student table, hold the mouse button down and
drag to StudentNumber in the Mark table, then let go of the mouse button.
 In the Edit Relationships window, tick Enforce Referential Integrity and Cascade
Update Related Fields only, then click Create.

Figure 13 – how the relationships should look

 Make sure that your relationships match the above – if not, delete the offending
relationships and go back to see what you did wrong!

12
Access 2010: Building Access databases (acc-39)

 If all is well, click on the Close button and save changes when asked.
7.7 To check the Student/Mark relationship and add some marks:

 Open the Student table and notice the plus sign next to the Student ID field – click
on the plus sign to open the sub-table for student number 1 and add the following
sets of marks (Mark code is filled in automatically, so just start by typing in the
Submission date field).
Submission Title Type Mark Comments
Date
01/03/12 Death on the Nile Essay 75 Late
01/03/12 Dial M for Murder Essay 95 Very inventive
01/06/12 English Part 1 Exam 55 Needs resit
01/11/12 LANG10031 Module 50

 Add some marks for students 2 and 3 (make it up!) then close the Student table.

13
Access 2010: Building Access databases (acc-39)

Task 8 Create a dropdown list not based on a


relationship
Objectives To create a dropdown for the Gender field based on bespoke values that you
choose. To see how to amend the list should you want to change the options
available in the dropdown.
Comments The same as with lookups created between foreign and primary keys, any forms
created after you have created a bespoke dropdown list in the table design will
automatically include the dropdown on the Gender field (if selected) from now on..

8.1 To create a dropdown list for the Gender field:


Note Always make sure that the field size is big enough to accept all of the data items in
your list!
 Make sure that all objects are closed, then open the Student table in Design View.
 Click in the Data Type field for Gender and choose Lookup Wizard from the
dropdown.
 Select I will type in the values that I want and click on Next.

Figure 14 – add in the items you want in your dropdown list

 Type in Male, Female and Undisclosed as per the screenshot above and click
Next.
 Tick Limit To List and click on Finish.
 Look at Datasheet View (saving when prompted) and try out your new dropdown by
randomly changing a few genders.
8.2 To amend this list:
 Go back to Design View, select Gender then click on the Lookup tab in Field
Properties.
 In Row Source add a semi-colon after “Undisclosed” and add “Fish” (with the
speechmarks).
 Look at Datasheet View (saving when prompted) and try out your new dropdown to
see the new option.
 Go back to Design View and revert to the original list, unless you really do want
Fish in the list!
 Whatever you decide to do, don’t forget to close the table.

14
Access 2010: Building Access databases (acc-39)

Task 9 Create a form and subform using Form Wizard


Objectives To create a form with subform based on the Student and Mark tables respectively.
Comments To create a form with subform there must be a relationship between the tables used.

9.1 To create a form with subform using Form Wizard:

Figure 15 – select Form Wizard

 In the Create section of the Ribbon, select Form Wizard from Forms.
 From the Tables/Queries dropdown list choose Table: Student.

Figure 16 – select the fields from the Students table as shown

 Double-click on StudentNumber, Subject, YearNumber, FirstName, LastName


and DateOfBirth to move them to the Selected Fields box.

Figure 17 – select all fields except StudentNumber from the Marks table

 Now select Table: Mark from the Tables/Queries dropdown and move all fields
except for MarkID and StudentNumber across, then click Next.

15
Access 2010: Building Access databases (acc-39)

Figure 18 – ensure the wizard screen is the same as above

 Select to view your data by Student, if not already the default, and click Next.
 Choose Datasheet as the layout for your subform, then click Next.
 Name the form as MyStudentForm and the subform as MarkSubform, then click
Finish.

Figure 19 – a very basic form with subform – colours may differ depending on setup

 Notice that the data entry fields are different sizes with data aligned left or right
depending on field size assigned and data type.
 Use the navigation buttons at the very bottom of the window (not those under the
subform) to move between records – note that any marks you added for student
numbers 2 and 3 earlier will appear in the subform when you move to those records.
 In the Home tab, click on the dropdown in the Views section and select Design
View ready for the next task.

16
Access 2010: Building Access databases (acc-39)

Task 10 Customise your form – basics


Objectives To make the form look and work the way you want it to.
Comments Every object on a form can be resized, re-coloured or otherwise reformatted.

Moving and resizing


10.1 To change the appearance of a field, label or other object:
 Click on the object once so that ‘handles’ appear.
 Try each of the actions in the two tables below by using the method suggested (you
must click on the object to select it first).

Figure 20 – moving the field and label together

Action Method
To move a field and label together Move the mouse pointer over the edge of an object so that a
(Figure 20) four-headed arrow appears, then click and drag the box to a
new position.
To move a field without moving the Move the mouse pointer over the larger handle at the top, left-
label, or vice versa (Figure 21) hand corner of the field control, then click and drag it to a new
position.

Figure 21 - moving one part of the field by clicking on the large ‘handle’

Action Method
To move selected controls with Click on a field control and press CTRL+ARROW keys to move
micro movement in the direction of the arrow.
To change the size of an object Move the mouse pointer across the handles until a double-
(Figure 22) headed arrow appears, then click and drag to the required
size.
To size selected controls with micro Press the SHIFT+ARROW keys.
movement

Figure 22 – resizing a field (double-headed arrow)

17
Access 2010: Building Access databases (acc-39)

Formatting options
10.2 To find out what the various toolbar options can do:
 Click on the Format tab of the Ribbon, and look at the various options – some
should be familiar as they are the same as those found in other Office applications.
 Select a Text box (data field) and try changing the font and font size.
 Experiment further on both fields and labels.

Figure 23 - formatting toolbar

 You can also format objects, such as field controls and labels using the Special
Effect option by right-clicking on an object and choosing one of the options.
 Have a look at the other options that you have on the right-click menu, especially at
Align and Position, which can be quite useful (these options are also available on
the Arrange tab in the Sizing & Ordering section).

Figure 24 – available Special Effects options

Controls and adding new objects


10.3 To add a title to your form:

Figure 25 – the Controls section of the Ribbon

18
Access 2010: Building Access databases (acc-39)

 Click on the Design tab to view the options in the Controls section.
 Click once on the label in the Form Header that says MyStudentForm and press
DELETE on the keyboard.

Note You could just have altered the text in the original label, but then you wouldn’t have
found out how to add a label!
 In Controls, select Label by clicking once.
 Place the mouse on the screen in the Form Header space (the cursor should
change to +A – as in Figure 26), hold the mouse button down and draw a box.

Figure 26 – the cursor changes to +A

 In the label box, type a suitable title, alter the size and colour of the text (you will
need to return to the Format tab) and resize the box if necessary (Figure 27) – you
will need to click outside of the box and then click once back on it before you can
format any text that you have added.

Figure 27 – the new form header label

Note Fields and labels can be deleted by selecting them and pressing the DELETE key. If
you select the field and press DELETE, this will delete both the field and its label. If
you select just the label and press DELETE, this will delete only the label.

Format Painter
10.4 To use Format Painter:
 In the Format tab, right-click on a data field and use the Fill/Back Color, Font/Fore
Color and Special Effect options to change the colours of the background, the text
and the text box in turn.
 Click away from the field (somewhere on the form, rather than on another object)
and then click back on to the chosen field once to make sure that it is selected.
 Click the Format Painter icon, and then select the next field to which you
want to apply the formatting.
 To copy the selected formatting to several locations, double-click Format
Painter and then click once on each of the objects that you want to format.
 Click Format Painter again to switch it off.

19
Access 2010: Building Access databases (acc-39)

Selecting and formatting multiple fields


Note You can select a number of fields at the same time so that formatting, sizing and
alignment can be carried out in a single operation.
10.5 To select multiple objects if they are located together:
 Move to a point above and to the left of the first object, hold down the left mouse
button and drag a rectangle down over the final object to be selected.

Figure 28 –selected objects are highlighted

 Release the left button and all the objects enclosed by the rectangle will be selected.
10.6 To select multiple objects if they are not located together:
 Click once on the first object.
 Hold down the SHIFT key and click on the other objects once each in turn.

Aligning and sizing objects


10.7 To align and size multiple objects:
Note All objects when moved automatically snap to grid to make positioning of objects
more uniform.
 Once you have selected several fields, select the Arrange tab.
 Align the selected field controls to each other by selecting Align, then choosing from
Top, Bottom, Left or Right as your form design requires (Figure 29).

Figure 29 – the Align options

20
Access 2010: Building Access databases (acc-39)

 To make the fields uniform in size to each other, click on the Size/Space
icon and select To Tallest, To Shortest, To Widest or To Narrowest
as your form design requires.
 Also use the Size/Space icon to experiment with the various options in the Spacing
section (at least three vertically spaced controls should be selected for the Equal
Vertical options).
Note If you get unwanted results, select Undo on the toolbar and try again selecting only
the field controls and not the labels.
 Look at how the form looks in Form View (Figure 30).

Resizing and repositioning the subform


10.8 To resize and reposition the subform:
 Click on the Mark label to the left of the subform and press DELETE on the keyboard.
 Click once and hold down the mouse on the subform and drag to the desired
position.
 Use the handles to resize the subform so that you can see all of the available fields
in the subform.
10.9 To add another field from the Student table:
 Click on the Add Existing Fields icon in the Tools section of the Design tab in the
Ribbon.
 Click on Gender and drag across to the form.
 Notice that it comes with dropdown attached – this is because the lookup was added
in the table design – and also note that it comes across unformatted.
 We don’t actually want the Gender field, so click on it to select it, if not still selected
and press the DELETE key.

Figure 30 – how your form with subform might look

21
Access 2010: Building Access databases (acc-39)

Task 11 Customise your form using the Property Sheet


Objectives To fine-tune the form and the objects on the form using the Property Sheet.
Comments The property sheet can be quite overwhelming when you first look at it, but just
remember that you will only ever use a few of the options available. Most options let
you do the same things that you will probably do manually, such as changing
colours and resizing things.

Properties
For several of the following tasks you will need to use the Property Sheet. As you
become more experienced in fine-tuning the controls on your form, you will find that
it is useful to keep the Property Sheet open whilst designing your form.
11.1 To open and get to know the Property Sheet:
 In Design View go to the Design tab of the Ribbon and select Property
Sheet.

Figure 31 - properties box

 Look at various of the tabs – and don’t panic! – yes, there is a lot you can do here,
but most mortals use very few of these options.

Replacing Layout View with Datasheet View


When trying to move between Form View and Design View, you have to keep using
the dropdown instead of just toggling between the two. Layout View gets in the way.
So do we need Layout View? The answer is no – all it does is let you make a few
format changes, but does not give as much freedom as Design View. Datasheet
View is much more useful because it lets you see multiple records at the same time.
11.2 To remove Layout View and add Datasheet View:

Figure 32 – notice that a small, black box appears when you click on it

 In Design View, click on the small box in the top, left-hand corner of the form. This
means that you have selected the form as a whole.

22
Access 2010: Building Access databases (acc-39)

 In the Properties Sheet and select the Format tab.

Figure 33 – you can change which toggle options you see under the Format tab

 Change Allow Layout View to No and change Allow Datasheet View to Yes.
 View the form in Datasheet View, then return to Design View. Notice that you now
toggle directly between Form View and Design View – that’s much better!

Locking fields and removing them from the tabbing list


Note For some databases, it is important that users should not be allowed to change the
values of certain fields; a student reference number would be an example. This can
be achieved by locking the field.
11.3 To lock a field:
 Make sure that the Property Sheet is open and click on the YearNumber field.
 In the Property Sheet, select the Data tab and set Locked to Yes (Figure 34).

Figure 34 – set Locked to Yes

 Test out the locked field by looking at Form View and trying to edit the data in the
field which you have locked.

Changing the order of data entry (tabbing order)


Pressing the TAB key moves from one data field to the next. However, if you have
moved fields around in Design View, then the tabbing order is likely to be wrong.

23
Access 2010: Building Access databases (acc-39)

11.4 To change the order of data entry tabbing on the form:


 In Form View, try TABBING from field to field and see if the order is odd.
 In Design View, go to the Design tab and select Tab Order.

Figure 35 - changing the tab order

 In the Tab Order dialogue box change the order of the fields by clicking once on the
grey box to the left of the field name.
 Click on the box (which is now black) and drag the field to a new position in the list.
 When the order is correct, click on OK.
Note The Auto Order option doesn’t always work as might be expected!
11.5 To stop tabbing into a field:
There is no point in tabbing into either StudentNumber or YearNumber –
StudentNumber cannot be edited because it is an autonumber and you have locked
YearNumber earlier in this task.
 In Design View click on StudentNumber.
 Select the Other tab in the Property Sheet and change Tab Stop to No.
 Do the same for YearNumber.
11.6 To stop tabbing into the subform:

Figure 36 – click the subform – make sure there is no black square in the circled area

 Click once only on the square in the top, left-hand corner of the subform.
 Open the Properties Sheet, select the Other tab, then change Tab Stop to No.

24
Access 2010: Building Access databases (acc-39)

Adding an image
www.bristol.ac.uk/imagelib holds a library of corporate graphics which you can use.
11.7 To insert an image onto your form:
 Right-click on an image on the webpage and select Copy.
 Right-click in the Form Header and select Paste from the menu that appears.
 Notice that the picture is placed inside a box, which can be resized.
11.8 To format the image to taste:
 Resize the box and see what happens to the picture inside.
 Open the Property Sheet if it is closed and select the Format tab.

Figure 37 – Size Mode properties

 Click on Size Mode and experiment with the options available from the dropdown
list: Stretch shows the whole picture stretched to outline; Zoom shows the whole
picture in proportion (Figure 37).

25
Access 2010: Building Access databases (acc-39)

Task 12 Add a calculation to a form


Objectives To add a calculated field to work out age.
Comments You must use the Text Box control to create a calculated field. Do not confuse the
Text Box and Label options. Note that calculations in text boxes must start with =.

12.1 To add a calculated field to work out age:


 In Design View, select the Design tab on the Ribbon and click the Text
Box button once and let go.
 Click on the form where you want the calculated field to appear.

Figure 38 – make sure that you type the right number of brackets!

 In the text box, type =int((date( )- DateOfBirth)/365.25) then go to Form View and
change the year of someone’s date of birth.
 Save the record and see the result.
12.2 To name the new field control:
 Click once on the text box and in the Property Sheet select the Other tab.
 Note that the Name property shows the same name as that shown on the label to
the left of the text box.
 Change the Name property of the text box to Age.

Important ‘gotcha’: the label and the text box both have their own names – don’t
get caught out by thinking that if you change the text on the label then that means
that you have given the text box a new name. All you will have done is changed the
text on the label. It doesn’t even rename the label – you have to do that the same
way as you have just renamed the text box!

Figure 39 – how the new text box and label should now look

 Change the text on the label to Age: – including the colon – and format the new field
to match your other fields.
12.3 To check the new field in Datasheet View:
 Switch to Datasheet View and notice that, although Age appears, it cannot be
edited or even sorted.
 In which case, you might as well stop the new field being tabbed into – if you can’t
directly edit the field, there’s no point tabbing into it.
26
Access 2010: Building Access databases (acc-39)

Task 13 Introducing automation


Objectives To add buttons to make navigating between records and finding records easier; to
create an autoexec macro that runs as soon as you open the database.
Comments This task is optional and will only be covered on the course if we have time. This
task only touches the surface – buttons can be fun and, if you want to get
complicated, you can create complex macros and create buttons to make them run!

13.1 To add buttons to go to next, previous and new blank records:


 Open MyStudentForm in Design View.
 Click once on the Button option in the Controls section and click once on
the form to start the Button Wizard.

Figure 40 – select these options from the wizard

 Select Record Navigation followed by Go To Next Record, then click Next.


 Name the button NextRecordButton and click Finish.
 Now create a button to go to the previous record – name it PreviousRecordButton.
 Create a new button based on Record Operations and Add New Record and name it
as NewRecordButton.
 Move the buttons to where you want them and format them to taste (you may want
to play around with the Quick Style and Change Shape options in the Format tab
in the Ribbon).
 Go to Form View and test your new buttons
13.2 To create a button to find a specific record:
 Create a new button based on Record Navigation and Find Record.
 Choose either text or picture and name the button FindRecordButton.
 Go and test the button (think back to the Access 2010: an introduction course to
remember how to use the Find dialogue).

27
Access 2010: Building Access databases (acc-39)

Figure 41 – how your form might look with buttons added

If you have time: depending where you put your buttons (i.e. if you put them in the Detail section of
the form) you may need to change the tabbing order*.
* Now do you see why you should to give buttons annoyingly long names that explicitly state what it is
that they do?

13.3 To create an ‘autoexec’ macro that tells Access what to do when you open
the file:
 In Design View, click on the Create tab and select Macro.

Figure 42 – the wonderful (and potentially complicated) world of macros

 Click on the dropdown and select OpenForm and in Form Name select
MyStudentForm.
 Click on the Save icon above the File tab, save the macro as Autoexec and close
the database, saving any changes if asked.
 Open the database again – MyStudentForm should now open automatically – on
opening any database file, Access always looks for a macro named ‘autoexec’.

28
Access 2010: Building Access databases (acc-39)

Task 14 Create a form that asks you what data you want
to see
Objectives To create a query that asks you which records you want to see and to create a new
form based on this query.
Comments This task is optional and will only be covered on the course if we have time. What
this task is intended to show is that it is possible to use queries to affect the way in
which you interact with parts of your database. In this instance you are creating a
form that filters the possible data records that can be shown in that form.

14.1 To create the parameter query:


 Create a new query and add the Student table.
 Add StudentNumber, Subject, YearNumber, FirstName, LastName and
DateOfBirth to the QBE grid.

Figure 43 – don’t forget to add the square brackets

 In the Criteria row for YearNumber enter [Which year?].


 Save the query and name it ParameterQueryForForm.
 Select Datasheet View and when prompted for a year, enter a number between 1
and 5.
14.2 To create a form on which to base the query:
(You could create a new form using the Form Wizard option and selecting the new
query as the data source, but then we will have to spend ages formatting it to make
it look good. Instead, and just to point out how it is done, we will make a copy of
MyStudentForm and assign the new query as the data source. It’s not for nothing
that we chose exactly the same fields that appear on the original form!)
 Close any open objects, right-click on MyStudentForm in the Navigation Pane and
select Copy.
 Right-click on MyStudentForm, select paste and name it ParameterForm.
 Open ParameterForm in DesignView and delete the subform (click once and hit
the DELETE key).

29
Access 2010: Building Access databases (acc-39)

Figure 44 – select the whole form

 Click on the square box in the top, left-hand corner of the form to select the form as
a whole, then open the Property Sheet if it is not already open.
 Select the Data tab and click on the dropdown next to Student in Record Source.

Figure 45 – the Form properties should look like this

 From the list, select ParameterQueryForForm.


Note Depending on setup, you will find the Caption option in one of two places – on the
Training Room PCs you will find it under the Format tab – it may be under the Data
tab on your staff PC however!
 Now, either directly underneath Record Source or top of the list in the Format tab
(see note above), change Caption from MyStudentForm to ParameterForm, then
save the changes. (Yes, it is annoying that you have to remember to change the
caption! Otherwise the tab will show the old form name.)
 Go to Datasheet View and enter a relevant year to test your new form. (It is easier
to see multiple results in Datasheet View.)

30
Access 2010: Building Access databases (acc-39)

Appendix A Setting a tabbed display


14.3 To set tabbed object display as default:
 Click on the File tab and click on Options.
 Click on Current Database and under Document Window Options, select Tabbed
Documents.

Figure 46 – select Tabbed Documents

 A message will tell you that you need to close the database for the change to take
effect, so click on OK.
 Click on the File tab and select Close Database.
 Reopen the database, click on Enable Content and choose No if a further security
warning appears.

31

You might also like