Access XP Intermediate
Access XP Intermediate
Intermediate
November 2002
Access XP Intermediate Course
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
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
6
Access XP Intermediate Course
7
Access XP Intermediate Course
Click
8
Access XP Intermediate Course
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
Once you have set the options desired click and the tables will be imported
10
Access XP Intermediate Course
Select the file from which you wish to link the data and click
Select the relevant tables and click
option if it has.
Click
11
Access XP Intermediate Course
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
13
Access XP Intermediate Course
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]
14
Access XP Intermediate Course
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.
15
Access XP Intermediate Course
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
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
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.
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
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
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
21
Access XP Intermediate Course
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
\
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
24
Access XP Intermediate Course
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
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
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.
27
Access XP Intermediate Course
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
29
Access XP Intermediate Course
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
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
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
Note You can press CTRL+BREAK or ESC to stop the compact and repair process.
33
Access XP Intermediate Course
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.
34