0% found this document useful (0 votes)
9 views34 pages

Access XP Intermediate

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)
9 views34 pages

Access XP Intermediate

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/ 34

Microsoft Access XP

Intermediate

November 2002
Access XP Intermediate Course

Copyright © 2002 University of Greenwich

All rights reserved. Except as permitted under current legislation, no part of this work may be
photocopied, stored in a retrieval system, published, adapted, transmitted, recorded or reproduced
in any form or by any means, without the prior permission of the copyright owner.

Microsoft Access and Microsoft Windows are registered trademarks of Microsoft Corporation.
Access XP Intermediate Course

CONTENTS

Lesson 1 What is importing?...................................................................................................................................... 7


Lesson 2 Importing data from an Excel File............................................................................................................. 8
Preparation................................................................................................................................................................ 8
Importing .................................................................................................................................................................. 8
Lesson 3 Importing data from an Access File......................................................................................................... 10
Lesson 4 Linking to Excel or Access data ............................................................................................................... 11
What is linking?...................................................................................................................................................... 11
Linking tables from another Access database......................................................................................................... 11
Linking a table from an Excel spreadsheet ............................................................................................................. 11
Lesson 5 Exporting data ........................................................................................................................................... 12
Exporting to Excel .................................................................................................................................................. 12
Exporting to Access................................................................................................................................................ 12
Lesson 6 OLE Objects as Data................................................................................................................................. 13
What are OLE Objects? .......................................................................................................................................... 13
Adding an OLE Object field to a table ................................................................................................................... 13
Adding OLE Objects to a field or Control.............................................................................................................. 13
Lesson 7 Hyperlink fields.......................................................................................................................................... 14
What are hyperlink fields for? ................................................................................................................................ 14
Adding an hyperlink field to a table ....................................................................................................................... 14
Adding web addresses to a field or Control............................................................................................................ 14
Adding Email addresses to a field or Control......................................................................................................... 14
Lesson 8 Freezing columns in Datasheets .............................................................................................................. 14
Why freeze columns? ............................................................................................................................................. 14
How to freeze columns ........................................................................................................................................... 14
How to remove the frozen columns........................................................................................................................ 14
Lesson 9 Sorting data ................................................................................................................................................ 15
Using the toolbar .................................................................................................................................................... 15
Lesson 10 Finding data ............................................................................................................................................. 15
Lesson 11 Creating indexes with multiple fields: ................................................................................................... 16
Why use indexes? ................................................................................................................................................... 16
Creating an index.................................................................................................................................................... 16
Lesson 12 Filtering data............................................................................................................................................ 17
Filter by form.......................................................................................................................................................... 17
Filter by selection ................................................................................................................................................... 17
Filter excluding selection........................................................................................................................................ 17
Advanced Filter/Sort............................................................................................................................................... 17
To Remove a Filter ................................................................................................................................................. 17
Lesson 13 Cascading relationships .......................................................................................................................... 18
Cascade Delete........................................................................................................................................................ 18
Cascade Update ...................................................................................................................................................... 18
Setting Cascade options for a new relationship ...................................................................................................... 18
Setting Cascade options for an existing relationship .............................................................................................. 18
Lesson 14 ‘Find Duplicates’ Query.......................................................................................................................... 19
What is this? ........................................................................................................................................................... 19
Creating the query................................................................................................................................................... 19
Lesson 15 ‘Find Unmatched’ query......................................................................................................................... 21
What is this? ........................................................................................................................................................... 21
Creating the query................................................................................................................................................... 21
Lesson 16 Totals query.............................................................................................................................................. 23
What is this? ........................................................................................................................................................... 23
Access XP Intermediate Course

Creating the query................................................................................................................................................... 23


Lesson 17 Cross tab query........................................................................................................................................ 25
What is this? ........................................................................................................................................................... 25
Creating the query................................................................................................................................................... 25
Lesson 18 Changing the look of the Form............................................................................................................... 26
Lesson 19 Changing Form Control Properties ....................................................................................................... 27
Lesson 20 Calculated values on forms ..................................................................................................................... 28
Example of totalling calculation ............................................................................................................................. 28
Example of text joining calculation ........................................................................................................................ 28
Example of Conditional statement.......................................................................................................................... 28
Nested IIFs.............................................................................................................................................................. 29
Lesson 21 Enabling and Locking controls on forms .............................................................................................. 30
Enabled ................................................................................................................................................................... 30
Locked .................................................................................................................................................................... 30
Locked and Enabled combinations ......................................................................................................................... 30
Lesson 22 Adding a tab control to forms ................................................................................................................ 31
What is the purpose of a tab control? ..................................................................................................................... 31
Adding a tab control ............................................................................................................................................... 31
Selecting a page ...................................................................................................................................................... 31
Adding controls to a page ....................................................................................................................................... 32
Adding another page............................................................................................................................................... 32
Renaming pages...................................................................................................................................................... 32
Total number of pages? .......................................................................................................................................... 32
Lesson 23 Compact and repair the database .......................................................................................................... 33
What is compacting? .............................................................................................................................................. 33
What is repairing?................................................................................................................................................... 33
When and how should I compact and repair?......................................................................................................... 33
While the database is open ..................................................................................................................................... 33
Before you open the database ................................................................................................................................. 33
Compact and Repair automatically......................................................................................................................... 33
Lesson 24 Database splitter ...................................................................................................................................... 34
Why split a database? ............................................................................................................................................. 34
Splitting a database ................................................................................................................................................. 34
Access XP Intermediate Course

Copyright © 2002 University of Greenwich

All rights reserved. Except as permitted under current legislation, no part of this work may be
photocopied, stored in a retrieval system, published, adapted, transmitted, recorded or reproduced
in any form or by any means, without the prior permission of the copyright owner.

Microsoft Access and Microsoft Windows are registered trademarks of Microsoft Corporation.
Access XP Intermediate Course

The Database used in the course


The intermediate course builds upon the database Invoice.MDB which was created during the
introductory course.

6
Access XP Intermediate Course

Lesson 1 What is importing?


If you are setting up a database data for one or more of the tables may already exist in another
application, e.g. Excel. Importing is the means used to bring that data into a Microsoft Access
table. Once the data has been imported it will exist both in the original application and in the
Access table. Updating the data in the original application will have no effect on the data in
Access. Conversely, updating the data in Access will have no effect on that in the original
application.
Data can be imported from:
• Another Access database
• Other databases: - dBase 5, dBase III, dBase IV, Paradox and databases accessed via
ODBC (Open DataBase Connectivity language)
• Spreadsheets: Excel, Lotus 123
• Email Programs: - Outlook, Exchange
• Text files: - .csv, .txt etc (where each item of data is separated by a comma, or space etc)
• Web formats: - .xml files (eXtensible Markup Language)
The procedure for Importing will vary depending on the type of data you are importing. The
procedures for importing data from Excel and Access are detailed here.

7
Access XP Intermediate Course

Lesson 2 Importing data from an Excel File


Preparation
1. If you are importing to an existing table the fields in the import file must be laid out exactly
as they are laid out in the table to which you are importing, with the same field names
2. You must close all tables, queries, forms etc as you cannot import to a table which is open in
any way.
Make sure that any tables, forms queries etc are closed since you cannot import to an open table.
Importing
Select File, Get External data, Import
From the box at the bottom of the resulting
dialogue box select the type of data file which
you wish to import from.
Select the relevant drive in the Look in box and click on the file name. Click
Select the sheet on which
the relevant data appears.

Click

You will now need to look at the


data displayed and see whether the
first row contains headings. The
first row of the example does
contain headings and we would
therefore click the First Row
Contains Column Headings option
so that it contains a tick.
If you have no Column Headings
Access will only allow you to
import the data to a New Table
The display will then update to
remove the first row from the
display. Click
Choose whether you want to import the data into a
new table or an existing table.
If you choose to import to an Existing table you must select the name of that table. Click
and then as that is all the information that is required.

8
Access XP Intermediate Course

If you choose to import to a New table click


You can now click on each field and
define what the field name should be,
whether that field should be indexed
and whether you actually want to
import the field.
When you have made any necessary
changes click

You now need to consider a primary


key. If a suitable field already exists
click Choose my own primary key
and select he field name from the box
on the right.
If there is no suitable field you may
wish to click Let Access add primary
key in which case a new field called
ID will be added with the field type
autonumber.
You may also choose No primary key
and not define a primary key at this
stage, since you can deal with it later
in the table design if you wish.

When you are satisfied click

Define a suitable name for the table and click

Note that if any data is unsuitable for importing then you will see an error message. Access may
delete data in a field of a record if it cannot put that data into a field. This may happen if there is
text in a date field for example.

9
Access XP Intermediate Course

Lesson 3 Importing data from an Access File


You will be importing complete tables, queries, forms etc. You cannot import data from a table
in one database into a table in another database.
Select File, Get External data, Import
From the box at the bottom of the resulting
dialogue box select the type of data file which
you wish to import from.
Select the relevant drive in the Look in box and click on the file name. Click
Click the table(s)
which you wish to
import. (Click
to
import all tables)
(Click on the tabs at
the top for any other
objects and select
them)
You have the choice of
importing the whole
table, including data,
or just the table structure – without the data. If you define neither of these then the table and
data will be imported. To define that
you only want to import the table
structure click and the
options shown right are added to the
bottom of the dialogue box.
If you are importing several tables, ensure that the Relationships option under Import is ticked
and that will save you having to set up all the relationships again.
If you want to import the data in the tables make sure Definition and Data under Import
Tables has a dot in it. If you wish to import empty tables click Definition Only.
If you are importing Queries as Queries the tables which the query uses must exist in the
database it is imported to, otherwise it cannot run. If you choose to import Queries As Tables
the query will run, select the data and then a table will be created which contains that data. The
original tables are no longer necessary.

Once you have set the options desired click and the tables will be imported

10
Access XP Intermediate Course

Lesson 4 Linking to Excel or Access data


What is linking?
When you import data from a spreadsheet or database the data you have imported is copied from
the original source and placed in the current database. There is then no connection between the
two sets of data, so that if you change the data in the current database the data in the original
source remains unchanged.
When you link data from a spreadsheet or database the data exists only in the original source and
there is a pointer to it in the current database. This means that when you change the data in the
current database you are actually changing the data in the original source. This prevents two
different copies of the data from existing!
Linking tables from another Access database
Select File, Get External data, Link Tables

Select the file from which you wish to link the data and click
Select the relevant tables and click

The table(s) are now imported.


Looking at the database window you
will see that tables which actually
exist within the database have the
symbol to their left, while linked
tables have the .

e.g. (Customers is a linked table, Invoice is not)


Linking a table from an Excel spreadsheet
Select File, Get External data, Link Tables
In the first dialogue box, right at the bottom, change the File Type to Microsoft Excel e.g.

Find the relevant file, click to select it and click .

Click the relevant Worksheet name and click


Decide whether the data in the spreadsheet has headings at the
top of the columns and click the

option if it has.

Click

Type a name for the Table and click


You will be able to see that a table is linked to an Excel
spreadsheet by the symbol to its left in the database
window

11
Access XP Intermediate Course

Lesson 5 Exporting data


Exporting to Excel
If you want to manipulate data you may feel that you can do this more effectively in Excel.
Go to the database window and click on the name of the table you wish to export.
Select File, Export
Make sure that the option Save as Type at
the bottom of the dialogue box is set to
whichever version of Excel is relevant.
(The option shown allows you to import into Excel 97, Excel 2000 or Excel 2002
To export to an existing file click on the file name, to export to a
new file enter a new file name.

Click
You can now open Excel and view the file. Note that it will have
a new sheet named the same as the table you exported.
In the example shown right the Country table was exported.
Note if the Excel file already contains a sheet with the name you
chose, the data on that sheet will be overwritten. Data cannot be
added to an existing sheet
Exporting to Access
Go to the database window and click on the name of the table you wish to export.
Select File, Export
Make sure that the option Save as Type at the
bottom of the dialogue box is set to Access
To export to an existing file click on the file name, to export to a new file enter a new file name.

Click
Type a name for the table (or accept the existing
name)
Select whether you wish to export the structure
(definition) of the table with the data, or just the
blank structure

Click
The other database will now contain an unconnected copy of the table
Note if the Access file already contains a table of the same name the table will be overwritten.
Data cannot be added to an existing table using Export

12
Access XP Intermediate Course

Lesson 6 OLE Objects as Data


What are OLE Objects?
An object from another application e.g. a Microsoft Excel spreadsheet, a Microsoft Word
document, graphics, sounds etc. OLE objects can be linked to or embedded in a Microsoft
Access table.
For example, you could choose to store a photograph of each student in their record.
Adding an OLE Object field to a table
Open the table in design view and insert the new field name. Give it the data type OLE Object.
Adding OLE Objects to a field or Control
In the datasheet view, or on a form, right click in the OLE object field and selelct Insert Object
In the dialogue box shown right click
the Create from File option.
The dialogue box will change to show
the options :

Click Browse to select the file you


wish to import.
You must also decide whether you wish to inport a copy of the object which is then stored in the
database and has no relationship to the original file, or whether you wish to Link to the original
file. To make a copy leave the Link option unticked. To link make sure that you tick the Link
option.
Click OK
Note that if you change the original file and you have not linked the file then those changes are
not made to the file stored in the database.
If you are in datasheet view and you have imported an OLE object you will only see a
description of the type of object
e.g.

If you are in a Form you will see the actual object,


as shown right.

You can edit the files by double clicking on the


field . Again, note that if the file was linked the
changes you make through the field are made to the original file – if it was not linked the
changes are made only to the file you have stored within the database.

13
Access XP Intermediate Course

Lesson 7 Hyperlink fields


What are hyperlink fields for?
These have two purposes. You can use them to store a web address, or someone’s Email
address.
If a web address is entered the user can click the web address and the browser (e.g. Internet
Exlorer) will be opened with the relevant address shown.
If an Email address is entered, when the user clicks the Email address an Email package will be
started, with a new message addressed to the Email address.
Adding an hyperlink field to a table
Open the table in design view and insert the new field name. Give it the data type hyperlink.
Adding web addresses to a field or Control
Simply type the full web address into the field and it will automatically be shown as a link

e.g.
Adding Email addresses to a field or Control
You must precede the Email address with the word mailto followed by a colon
e.g. mailto:[email protected]

Lesson 8 Freezing columns in Datasheets


Why freeze columns?
If you are working with data in the datasheet view of a table you may be frustrated by the fact
that when you move to the end of a record you have lost the identifying fields at the beginning of
the record.
You can choose to hold some columns still so that they remain on screen as you scroll to the
right and this is called Freezing columns
How to freeze columns
Click the buttons with the field name at the top of the column you wish to freeze. If there is
more than one column you wish to freeze click the first one, hold the mouse button down and
drag to select all the desired columns. Note that the columns must neighbour one another.
Once the column(s) are selected select Format, Freeze columns
How to remove the frozen columns
To stop the columns from being frozen select Format, Unfreeze all columns
Freezing multiple columns which are not neighbours
Select a column and freeze it as before. Select the next column and freeze it.
Note that each column you freeze is moved to the left. When you choose to unfreeze all columns
these columns will not be moved to their original places.

14
Access XP Intermediate Course

Lesson 9 Sorting data


The data is automatically sorted by the primary key.
To sort by any other field, click in the column by which you select Records, Sort and then click
on either ascending or descending. The data will immediately be sorted
If you wish to sort by more than one field then use Filter/Sort as explained in the next task

Using the toolbar

You can also use the buttons . The first sorts alphabetically or numerically and the
second sorts in reverse alphabetical or numerical order. Click on the heading of the column that
you wish to sort by and click on the relevant button.
If you click and drag across two columns the left-most column will be sorted first, and the next
on the right will be sorted within the first.

Lesson 10 Finding data


You can search for a specific value within a field.
First click on the
heading for the field
which you wish to
search, then select Edit,
Find or click on the
button.
Type the value for which
you wish to search in the
Find What: box.
Look in: Make sure that this shows the name of the field in which you wish to search for text. If
it does not you should close the Find and Replace box, click in the field you wish to search
and then click again.
To search through the whole table and not just one field, click the Look in: field and select
the name of the table.
Match: Consider whether the value will form the whole of the field, part of the field, or just the
start (e.g you could define the first letter of a word) and select the relevant option
Search: Choose whether to search through the table from where you are to the end (Down), or to
the beginning (Up) or the whole table (All).
Match Case: if this is ticked Find will find only values which have identical case to that typed
in the Find What box. i.e if you type Gnat it will not find gnat
Search Fields As Formatted will be specifically useful with date fields. The date is stored as
numbers (e.g. 12/2/96) but may be formatted as 12 Feb 1995. Searching as formatting will
allow you to search for Feb
Click the Find Next button to find the first occurrence of the value. Click again to find each
succeeding value.

15
Access XP Intermediate Course

Lesson 11 Creating indexes with multiple fields:


Why use indexes?
An index helps Microsoft Access find and sort records faster. Access will look up the location of
the data in an index. Access automatically creates an index for the Primary key of a table. An
index can be based on a single field or multiple fields. Index fields which you use to search on
often. You cannot index an OLE object field. An index will not particularly speed searches
where many of the values in the field are the same.

If you often set criteria for a query which involve two or more fields then it may be useful to
create an index based on those fields. E.g. FirstName and FamilyName. You can have up to 10
fields in a multiple-field index.
Another reason is that of uniqueness. Where an autonumber field has been used as the primary
key, no checks are fulfilled on the uniqueness of any other fields. In our example, in the
Customer table the primary key is an autonumber field, which means that there is no way of
checking whether the same customer has been added twice. One way to try to rectify this is to
create an extra index consisting of perhaps CustomerName and Address1 and set this as a unique
index so that the same Customer name and first line address cannot be added again.
Creating an index
Select View, Indexes. All existing indexes will be listed, including the primary key index.
To create a new index, type an index name in the first column and select a field name in the
second column. To add another field to the index go to the next line and enter another field in
the Field Name column. Do not add another index name.
The index on the right is called name
check and consists of the three fields
Surname, First name and Organisation.
To make sure that no person can be added twice you must change the type of index. To do this
your cursor must be on the line which has the name of the index (Name Check in the above
example). At the bottom of the dialogue box you will see the
options shown on the right. Make sure that Unique is set to
Yes. This will ensure the combination of information in the
fields which make up the index cannot be repeated

16
Access XP Intermediate Course

Lesson 12 Filtering data


Filters are useful for temporarily changing the set of records you are viewing. They only work
with the table which you have open. Use Queries (see later tasks) for data across more than one
table, or when you frequently want to view a certain set of records in a certain order.
To filter data select Records, Filter. You will then see the menu
shown on the right.
Filter by form
(You can also click on the button on the toolbar)
This will produce a form with all the fields of the table. Click under each heading to select a
value from existing data, as required.
To apply the filter select
Filter, Apply Filter/Sort or
click on the button.
When a filter is being used the
filter button will be bordered
with blue

Notes:
The filter can be saved as a query by clicking on the button while editing the filter.
You can also open a previously saved filter using the button.
Filter by selection

(You can just click on the button) This will find any data which matches the data in the
particular field in which you have your cursor.
Filter excluding selection
(there is no shortcut button) This will show records excluding those with fields which match the
field in which your cursor was when you clicked the button.
Advanced Filter/Sort
This works just like a query (except that it used only one table) and can be saved as one.
To Remove a Filter
In order to view the whole data again you must either select Records, remove Filter/Sort or
click on the button so that the blue surrounding line disappears

17
Access XP Intermediate Course

Lesson 13 Cascading relationships

Cascade Delete
In our example database,
if you try to delete a
record in the Contact
table you will see the
error message shown on
the right. This is because there is data in the Contact Interest table which is related to that
record. The relationship is one Contact to many contact interests. The record at the one end
must exist before you can connect many records tot it. Logically, it would not make sense to
have interests for a contact who does not exist!
You will realise that deleting a contact is something that you may wish to do, if the contact
leaves the company etc. At present you would have to find all the records in the Contact
Interest table for that contact and delete each one before you can delete the record in the
Contact table. This would be time consuming (and irritating?) and since the records in Contact
Interest have no meaning without a matching contact it would be nice if we could delete both
sets of records at once.
You can! If you make the relationship between Contact and Contact Interest into a Cascade
Delete relationship when you delete a record in the Contact table all related records in the
Contact Interest table will be deleted automatically!
(Note that this only works when you delete a record in the table at the one end of the
relationship!)
Cascade Update
Similarly, in the Organisation Type table, if you try to change the Organisation Type code for
“Associations” from ass to Asn you will see a similar error message. This is because the
Contact table has a related field. The piece of data in the Organisation Type Code field in
Contacts must match one of the pieces of data in the Organisation type code field in the
Organisation Type table.
To successfully change the data you would have to delete the relationship between these tables,
make the change in all records in both tables and then recreate the relationship. This is a long
and laborious task! However, if we make the relevant relationship a Cascade Update
relationship then when we make a change in the table at the one end of the relationship that
change will be automatically made in the related records in the table at the many end.

Setting Cascade options for a new relationship


When you are setting up relationships (click on the
button) make sure the Enforce Referential Integrity
option is ticked and then click the Cascade Update
related fields option and/or the Cascade Delete Related
Records as relevant.
Setting Cascade options for an existing relationship

In the relationship window (click on the button) double click on the line representing the
relevant relationship and select the options required.

18
Access XP Intermediate Course

Lesson 14 ‘Find Duplicates’ Query


What is this?
If more than one person is entering data into the same database, (or you have a bad memory) it
can happen that the same data is entered more than once. This type of query enables you to be
able to check for duplicate data and deal with it.
Creating the query
Click the Queries button and then click
. Select the Find Duplicates
Query Wizard

At the first step of the Wizard (shown


right) you must select the table (or query)
which you want to check for duplicate
records.
Click the table name and click

Now select the fields which you wish to


use.
Note that if you use only Customer
Name in this example, you will find all
customers who have the same name.
One customer may have more than one
branch so this will not necessarily show
you duplicate records. Add another
field, such as the Postcode for example.
To use a field in the query click on the field name and then click the arrow to move it to the
box on the right. If you make a mistake you can use to remove the field from the right-
hand box.
When you have selected all the fields
which you wish to use click
You can then choose other fields whose
data you would like to see in the query.
You do not need to choose any fields
here – though it can be useful to add all
other fields in order to ensure that the
records are duplicates in every respect.
Click when you have finished

Type a name for the query and click

19
Access XP Intermediate Course

The query will be created and you will see the results.
Depending whether you chose to view additional fields or not you will see one of two types of
result
1. If you did not add additional fields you
will see the result as shown right
This example indicates that 2 records for the
Customer Jay and Son exist, duplicates in so
far as the fields CustomerName and PostCode are concerned.
2. If you added additional fields you will
see the result as shown right where each record
is listed separately.
In this case, once you are satisfied that the
records are true duplicates you can delete one of them. Click on the grey button to its left and
press the delete key on your keyboard.
Note though that you will be unable to do this if there are any related records in another table.

20
Access XP Intermediate Course

Lesson 15 ‘Find Unmatched’ query


What is this?
This gives the opportunity of finding records which have no matching records in another,
related, table.
For example, we may wish to find out if there are any customers in our database who have
received no invoices. i.e. a record for the customer exists in the Customer table but no
matching record exists in the Invoice table.
Creating the query

Click the Queries button and then click . Select the Find Unmatched Query Wizard
At the first step of the Wizard (shown right)
you must select the table (or query) in which
the records occur for which you wish to
check for matching records in another table –
e.g. the Customer table.
(Note that this will normally be the one end
of a relationship – unless your database
relationships are set up incorrectly!)
Click the table name and click

Click the table which should contain


records related to records in the first table
you chose. E.g. the Invoice table.
(Note that this will normally be the many
end of a relationship.)
Click

You must now define the field which the


two tables have in common.
If the fields have the same name Access
will recognise them and define them
itself, otherwise you must click on the
relevant field in each table and then click
the button.
When a matching field has been set click

21
Access XP Intermediate Course

Select the fields which you wish


to see in the query (fields which
will identify the record s which
have no match)
Click each field and click
to move them to the box on the
right (which shows the fields
included in the query) or click
to include all fields.
Use or to remove fields from the right hand box if you have made a mistake.
Click when you have selected all required fields
Type a name for your new query and click

The result will be a query listing records from the main table
with no matching records in the related table.

22
Access XP Intermediate Course

Lesson 16 Totals query


What is this?
This gives the opportunity of grouping data, of being able to count items etc. For example we
may wish to know the total amount involved on each invoice sent out, rather than each separate
amount., or we may wish to count how many invoices have been sent to each customer.
Creating the query
Start by creating a query in the usual way. Select
all tables required and add necessary fields. E.g. to
produce a query showing how many invoices have
been sent out to each Customer we would need the
Customer and Invoice table. We would need, say,
the CustomerName and InvoiceNo fields as shown
right.
The query so far will merely list all Customers with
their associated Invoices.
To show the number of invoices we must change
the query.
Select View, Totals
We now have an extra row in the query design titled Total
The text under each field name says Group by and so at
the moment we will still see each Customer and their related Invoice No.
What we want is the total number of invoices sent to a customer, so we Group by the
Customer, but change the option under InvoiceNo to show
Count
Viewing the result of the query will now show the number of
invoices for each Customer as shown right.
Note that the name of the field is now CountOfInvoiceNo. If
desired you can change this in design view by adding the
required name in front of the previous name followed by a colon,
e.g.
The query will not show any Customers for which there exists no
invoice.
You may only be interested in Customers based in England. In this case you will use the Total
option of Where and then type the criteria in the Criteria line. E.g.

\
Note that you can Group By more than one field and you can use any of the functions listed
below instead of Count. You can also use one function for one field and another for another
field if required.

23
Access XP Intermediate Course

For Numerical fields only:


Sum – adds the values within the defined group
Avg – calculates the average value for the defined group
Min – finds the minimum value within the defined group
Max – finds the maximum value within the defined group
StDev – calculates the standard deviation of values within the defined group
Var - calculates the variance of values within the defined group
For Text or Numerical fields
First – shows the first value for the defined group. (e.g. it would show only the first InvoiceNo
for Cherry Tree)
Last – shows the last value for the defined group.
Expression – this is used where a calculated field has been used. E.g. if we wanted to show the
total value of an invoice we must use the calculation Price* Quantity. Since this is a Total
query we must use the Expression option and also add the Sum function to the calculation,
Thus the design below. gives results as below, showing total amount
for all invoices sent to each company

24
Access XP Intermediate Course

Lesson 17 Cross tab query


What is this?
A Cross Tab query is the next stage from a Totals query. It allows you to group data according
to 2 or more fields, as does the total query, but it presents the data in a 2 dimensional table, with
one set of headings across the top and another down the side.
e.g
If we were interested in how products sell in
different countries we may produce a select
query, grouped by Country and Product which
would appear as shown right.
It is very difficult here to compare sales of,
say, Speakers in England and the USA.
We may prefer to change this to a crosstab
query, which would result as shown below:

Note that in the crosstab query on the left the


product is shown down the left and the country
across the top. It is now much easier to compare
the sales of Speakers in the two countries.
Creating the query
Once again we start by creating a normal select query. In the above example we would include
the Customer, Invoice, InvoiceLine and Product tables, and the Country and ProductName
fields.
Now change the query to a Crosstab query by selecting Query, Crosstab Query
You will see that the query now has the Total line as dealt with in the previous lesson, and also a
Crosstab row.
The Total line is completed automatically, but you must complete the details in the crosstab line.
Select at least one field to be a Row Heading (in the example shown above ProductName is the
row heading), only one field to be the Column Heading (Country in the above example) and only
one field to be the Value (the calculated Cost field in the above example).

Note: You can add a field in the query design grid and click (Not Shown) in the Crosstab cell
and Where in the Total cell The data will then be grouped on this field as if it were a row
heading. This allows you to type a criteria under the field
If the values in the Column Heading field includes characters usually not allowed in field
names, (e.g. fullstop) Access will replace the character with an underscore in the datasheet.

25
Access XP Intermediate Course

Lesson 18 Changing the look of the Form


Areas
The Form has, or can have, various different sections. There may be a Page Header, a page
footer, a form header, a form footer and there will always be a detail section. Anything that
applies to the form will be shown once at the beginning or end of the form. Anything that applies
to a page will be shown at the top or bottom of each page of the form. The detail section
contains the main body of the form.
Adding/ Removing Headers and Footers
If you do not have the form or page headers or footers you can select the View menu and click
on the option Page Header/Footer or Form Header/Footer. If the sections are already visible
the menu options will have a tick by them. In this case you could remove the sections by clicking
on the menu options.
Note: Page Headers and Footers will only be used when the Form is printed
Changing properties
You can change the look of each section by clicking with the right mouse button on the
background of the relevant section and selecting Properties
Some useful options are:
Can grow: If set to Yes this will allow the size of the form to expand as the information in the
controls expands
Can shrink: If set to Yes this will allow the size of the form to contract as the information in the
controls contracts
Back colour: To change the background colour click on the button at the right and click on
the colour of your choice
Special effect: You can choose from a raised effect, a sunken effect or neither.

Note: The Force New Page, New Row OR Col and Keep Together properties apply when the
form is printed out only.

26
Access XP Intermediate Course

Lesson 19 Changing Form Control Properties


You can change many things about the control and/or label, e.g. the font style and size, whether
it has a border etc. To change or view the existing properties, highlight the control or label in
which you are interested and select View Properties or click the button.
You can change the control name by typing
in a new name. (This is useful for macros etc.)
The Control Source shows the name of the
field to which the control is bound. You can
select from a list by clicking in this area and
then on the down arrow
You can set the Format, Decimal Places,
Input Mask and Default value as for Tables.

There are many properties, some very advanced, some simpler. The properties available will
vary between the different types of control. As you move into a property field you will see a hint
as to the use of that property shown on the status bar. Use the scroll bars to see more. Towards
the bottom you will find font options etc. as shown below. In general, if a property has preset
options you can see them by clicking in the field and then clicking on the down arrow which will
appear.

The Special effect gives you the option of giving the


control the appearance of being raised, sunken, etched
shadowed or chiselled.
Choose a style(i.e. dashed, dotted etc), colour and
width for a border if required
Choose a colour for the text within the control
Choose a style, size, weight for the font, and special
effects such as italics or underlining
Choose an alignment for the text within the control, i.e.
left, centred right

27
Access XP Intermediate Course

Lesson 20 Calculated values on forms


You can calculate values on a form by inserting an unbound control and typing the calculation
into the control, beginning with an = sign
Example of totalling calculation
The example shown right uses the Sum function to find the total amount spent on this Invoice
Note that we only wish to see this result once
per invoice, so it has been placed in the
Form Footer. If it had been placed in the
Detail area we would have seen the same
amount shown for each line of the invoice
The result of putting the calculation in the
Footer is shown below left. The result of putting it in the detail area is shown below right

Example of text joining calculation


You can also use the text joining calculation
e.g. =[Title]& " " &[FirstName]&" "&[Surname]
Note that there is a space between the quotes in the above formula, thus we are inserting a space
between each item of data.
Example of Conditional statement
One problem with the previous example is that if, for example, there is no Title the calculated
data will start with a space. If there is a Title, but no FirstName, then the Title and the Surname
will be separated by two spaces. E.g.
In this example it is only where all three items of data are present that the
calculation works out correctly!

To correct this problem we need to use the IIF statement which allows us to make conditional
arrangements. i.e. what we want to say is – If there is a Title, leave a space after it. If there is no
Title, don't leave a space.
The IIF statement has three parts: the criteria (Title is empty), what happens if the criteria is true
(no space), what happens if the criteria is false (a space), These three parts are separated by
commas and enclosed in brackets i.e. IIF(criteria, true, false)
The term Access uses for testing whether a field is empty is Is Null
So we can write the IIF statement as IIF([Title] Is Null, "", " ")
Note that there is nothing between the first set of quotes and a space between the second set.
This statement can then be inserted into our formula instead of the simple space between quotes

28
Access XP Intermediate Course

So the formula =[ Will result in:-


Note that Mr Brown still has two spaces! We have so far simply removed
redundant spaces at the beginning of the joined text.

So the formula will become

and the result as shown right


You can also use the IIF statement within a numerical calculation. Suppose we have a system
such that if someone orders 5 or more of any item they get a 10% discount, i.e they will pay 90%
of the price, (90% is 90/100 or .9)
The IIF statement would be IIF(quantity>=5, price *.9, price)
i.e. If quantity >= 5 is true they pay 90% of the price and if it is not true they pay the price.
This just sets what price is to be paid. To find out the cost of the purchase we need to put that
statement into the formula as
shown

which will give the result shown


right. Note that where Quantity is
less than 5 the Cost with and
without discount are the same. Where Quantity is 5 or greater the Cost with discount is less
than the normal cost.
Nested IIFs
You can also have IIF statements within IIF statements
Supposing that if 5 or more items are ordered the price charged is 90% of the full price, but if 20
or more are ordered the price goes down to 80% of the full price. The price calculation would
be:
Criteria 1 Criteria 1 TRUE Criteria 1
FALSE
Criteria 2 Criteria 2 Criteria 2
TRUE FALSE

IIF(Quantity >=5, IIF(Quantity>=20, Price *.8, Price *.9), Price)


Note: The IIF statement can be used in Queries and Reports too

29
Access XP Intermediate Course

Lesson 21 Enabling and Locking controls on forms


There are times when you wish to show field information on a form, but not allow users to
update it. (For example, the calculated information from the previous lesson!)
Create a control on the form for the field. Click the field and select View, Properties (or right
click and select Properties, or click the button on the toolbar)
Click the Data tab. The two properties which concern us here are Enabled and Locked

Enabled
If Enabled is set to Yes then the user can click to select the control and if you press the Tab key
on the keyboard the cursor will stop at the control. If it is set to No the user cannot click to
select the control and when pressing the Tab key the cursor will not stop at the control
In the example shown right InvoiceNo has its Enabled property
set to No whilst InvoiceDate has Enabled set to Yes.
You can change the setting from Yes to No quickly by double clicking
Locked
If Locked is set to Yes the user can change the contents of the control. If set to No the contents
cannot be changed.
There will be no difference in appearance between controls which have the Locked property set
to Yes and those set to No. In both cases you can click in the control and the flashing cursor will
show.
Again you can change the setting from Yes to No quickly by double clicking
Locked and Enabled combinations
It can confuse and irritate users when one control is greyed out (as when Enabled is set to No)
This can be avoided by judicial use of the Locked property. The results of the permutations of
the two properties are given below:,
Enabled Locked Result
Can have Focus* Can change data Display type
Yes No 9 9 Normal
Yes Yes 9 8 Normal
No No 8 8 Dimmed
No Yes 8 8 Normal
*If a control can have the focus it means that if you click the control the flashing cursor will appear in it.

30
Access XP Intermediate Course

Lesson 22 Adding a tab control to forms


What is the purpose of a tab control?
You may have a form which contains many controls. You may run out of space on the form for
all the controls you need, or you may just find that it is confusing to the user to wade through
lots of controls. You can create more space on a form, and organise controls better, by creating
different pages within the form. This is done using a tab control
The example below has a tab control consisting of 3 pages. The general information of the
person (Title, Initial, Surname, Contact First name, Spouse First name) is on the basic form. All
other information is grouped into three areas, Home Address, email and phone, Children and
Birthdays and Work Details. To see Work Details information you would click on the Work
Details tab.

Adding a tab control


Make sure you are in the design view of the form. Check that you can see the
toolbox (shown right) If it is not visible anywhere on the screen (and it may be a
horizontal bar with the other toolbars at the top of the screen) click on the
toolbar.
From the toolbox click on the button

Move the cursor onto the form and the cursor will change to . Hold the left
mouse button down at the top corner of the area in which you wish to place the pages, and drag
down to the bottom right of the area. Release the mouse button.
You will now see two pages (as shown right)
Selecting a page
When you are adding controls to a page you must ensure that the page is
selected first. Otherwise the controls will be placed on the main form and
not on the page.
Note the handles (small black selection markers) on the tab control shown
right. These indicate that the tab control is selected, and if controls are
added they will be placed on the main form and not on a specific page

31
Access XP Intermediate Course

Click on the actual page tab in order to select a particular page. Note
where the mouse pointer is in the example shown right, and note the
position of the handles. In this example the page is selected
Adding controls to a page
1. If the control already exists on the form and you wish to move it to a page you must click
the control and select Edit, Cut. Select the page as explained above and select Edit, Paste
Check that the control is shown only on that page by clicking on another page!
2. If the control does not already exist on the form, select the page as explained previously.
Make sure the field list is showing (click on the toolbar if is not) Click on the desired
field in the field list and drag it onto the selected page.
Check that the control is shown only on that page by clicking on another page!
Continue adding controls as required.
You can also add a subform to a page.
Adding another page
Click with the right mouse button on one of the tabs and select Insert Page
Renaming pages
Right click the relevant page tab and select Properties.
Click the Other tab and type a new name in the Name property. This new name will be shown
on the tab.
To rename another tab merely move the properties box (if necessary) so that you can see the next
tab and click on it. You will then see the properties for that page. You do not have to close the
properties box in between!
Total number of pages?
I can find nothing which states this, but I have added 100 pages. Obviously, the more data you
have on one form the slower it will be to load!

32
Access XP Intermediate Course

Lesson 23 Compact and repair the database


What is compacting?
When you delete data in the database the file can become fragmented and use disk space
inefficiently. When you compact the database Access rearranges the way the file is stored on
your disk. It can have the effect of making the file smaller.
What is repairing?

Microsoft Access can detect that a database is damaged and will attempt to repair it. Sometimes
it does not detect damage. If your database is behaving badly and causing problems it is worth
compacting and repairing it to see if Access can solve the problems.
Solvable problems may be: Corruption in a table, form or report or missing information that
Access needs to open a particular form or report
When and how should I compact and repair?
To ensure best use of a database you should compact and repair it regularly. You may also need
to do it when problems arise with the database. There are several ways to do this. Before trying
any of them you must ensure that no-one else has the database open
While the database is open
Select Tools, Database Utilities, Compact and Repair Database
Before you open the database
(This method is more efficient at minimising the size of the database – especially if you compact
into another file rather than using the same file name)
Close all databases.
Select Tools, Database Utilities, Compact and Repair database

Select the file which you wish to compact and click


In the next dialogue box type the name of a new database file (you can use the existing name and
Access will overwrite it) and click
Access will now compact and repair the database and place it in the new file.
Compact and Repair automatically
You can set the database so that it will automatically compact and repair when you close the file.
However, it will not happen if anyone else is using the database at the time you close it.
Open the relevant database
Select Tools, Options, click the General tab and ensure there is a tick in

Note You can press CTRL+BREAK or ESC to stop the compact and repair process.

33
Access XP Intermediate Course

Lesson 24 Database splitter


Why split a database?
It is advisable to break a database into two. One database consists of the tables and nothing but
tables, (referred to as the Back end) while the other consists of queries, forms and reports, with
linked tables from the first database (referred to as the Front End). There are two main reasons
for this:
• Updating of Forms, Queries and Reports. If there is only one database and updating is
necessary you will need to stop everyone using the database while the updating is carried
out. If the tables are in a separate database you can make a copy of the Front End database
and work on that, while allowing people to continue working on the database, adding and
altering data in the tables.
• Varying Forms, Queries and Reports. Different people may have different requirements
from the database. You can create various Front End files all linked to the same data source
(Back End) so that users can have customised forms etc.
Splitting a database
Make a backup copy of the database.
Open the database
Select Tools, Database Utilities, Database Splitter
The first screen warns you to make a backup, and that the splitting process could take a time.

Click
The next dialogue box asks you to define a name for the Back-End part of the database,
automatically suggesting the existing database name with _be after it.
E.g.

Type the name (if you want an alternative) and click

After a time you will see


The Front-End file will have the original name of the database, e.g. Customers.mdb, and you will
see that this has linked tables only, while the Back-End file has tables only.

34

You might also like