21
Introduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: [email protected] 1. Learning outcomes check list for the session ................................................................................... 2 2. Introduction............................................................................................................................................ 3 3. The consultations database ................................................................................................................. 3 4. Starting Access ..................................................................................................................................... 4 5. Getting help when in Access................................................................................................................ 4 6. How to create a Database in ACCESS ................................................................................................. 6 7. How to create a new table and fields in ACCESS............................................................................... 7 7.1 Adding fields ...................................................................................................................... 8 7.2 Saving your work ............................................................................................................... 9 7.3 Input masks ..................................................................................................................... 11 7.4 Moving between design and datasheet view ................................................................... 12 8. Working with records in datasheet view ........................................................................................... 13 8.1 Deleting records............................................................................................................... 14 9. Inserting / deleting or moving field definitions................................................................................. 14 10. Required field values ...................................................................................................................... 15 11. Creating Key Fields in Access ....................................................................................................... 16 11.1 Setting a Primary Key ...................................................................................................... 16 11.2 Removing a primary key .................................................................................................. 16 12. Closing an existing database ......................................................................................................... 17 Opening an existing database.................................................................................................................... 17 14. Consultations Exercise (creating the Con1 database)................................................................. 18 15. Resumé............................................................................................................................................. 20 16. Check what you have learnt ........................................................................................................... 20 17. Renaming or copying tables........................................................................................................... 21 18. References ....................................................................................................................................... 21 19. Answers to exercises ...................................................................................................................... 21 This handout is part of a course. For details of other material that should be read before this please see Section 7.1 at: http://robinbt2.free-online.co.uk/virtualclassroom/contents.htm

Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: [email protected] 1. ... 5 Doc ID Number long integer

  • Upload
    ngodien

  • View
    215

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Access97 (1):

Tables & Fieldsby Robin Beaumont

e-mail: [email protected]

1. Learning outcomes check list for the session ................................................................................... 2

2. Introduction............................................................................................................................................ 3

3. The consultations database ................................................................................................................. 3

4. Starting Access ..................................................................................................................................... 4

5. Getting help when in Access................................................................................................................ 4

6. How to create a Database in ACCESS................................................................................................. 6

7. How to create a new table and fields in ACCESS............................................................................... 7

7.1 Adding fields ...................................................................................................................... 8

7.2 Saving your work ............................................................................................................... 9

7.3 Input masks ..................................................................................................................... 11

7.4 Moving between design and datasheet view ................................................................... 128. Working with records in datasheet view ........................................................................................... 13

8.1 Deleting records............................................................................................................... 149. Inserting / deleting or moving field definitions................................................................................. 14

10. Required field values ...................................................................................................................... 15

11. Creating Key Fields in Access ....................................................................................................... 16

11.1 Setting a Primary Key ...................................................................................................... 16

11.2 Removing a primary key.................................................................................................. 1612. Closing an existing database ......................................................................................................... 17

Opening an existing database.................................................................................................................... 17

14. Consultations Exercise (creating the Con1 database)................................................................. 18

15. Resumé............................................................................................................................................. 20

16. Check what you have learnt ........................................................................................................... 20

17. Renaming or copying tables........................................................................................................... 21

18. References ....................................................................................................................................... 21

19. Answers to exercises...................................................................................................................... 21

This handout is part of a course. For details of other material thatshould be read before this please see Section 7.1 at:

http://robinbt2.free-online.co.uk/virtualclassroom/contents.htm

Page 2: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 2

1. Learning outcomes check list for the session

This practical sessions aims to provide you with a number of skills (the 'be able to's') along with relevantinformation (the 'know what's'). These are listed below. After you have completed the session you shouldcome back to these points ticking off those you feel happy with.

Learning outcome Tickbox

Be able to open up, and close down Access.

Be able to use the help system in Access.

Know what a table, form, query and report are alongwith their uses.

Be able to create a new Access database or open anexisting one

Be able to create tables and fields

Be able to save your database onto a floppy disc

Know how to rename or copy tables

Know what 'input masks' are and why they are used.

Be able to create 'input masks'

Know the difference between design and datasheetviews.

Be able to move between design and datasheetviews.

Be able to view, edit, insert or delete records.

Be able to create fields that require a value in them('non null')

Be able to create a primary key

Know how to delete a primary key

The exercise you will work through focuses on creating a database to collect data about consultations.

Page 3: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 3

2. Introduction

Access is fast becoming the most popular database for small projects. It is also often used to prototypethings that will eventually be developed in a more robust environment. Yes Access has bugs in it, in-fact alarge number! Much more expensive DBMSs (DataBase Management Systems) such as ORACLE arefar more bug free but much more difficult to use. You know you can trust your data in ORACLE. We willtherefore introduce you to databases in a relatively gentle manner.

3. The consultations database

During this session we will begin to develop a ‘consultation’ database which is designed to allow doctorsthe ability to collect information about various aspects of their patients and consultations. The databaseconsists of a number of tables one of which defines the data required from patients. The data dictionaryfor the 'patient' table is given below. If you are unsure what a Data dictionary is see 'ways f thinking aboutthe clinical information you collect - Data' from the main web site (http://wwwrobinbt2.free-online.co.uk/virtualclassroom/contents.htm). The patient table will be the first table you will create inACCESS97 during this session.

Patient Table details

Field number

(for referenceonly)

Field Name Field type Field size Description

1 Patient id number longinteger

The unique patientidentifier

2 Title text 15 Mr, Miss, Ms, Dr or Prof.

3 First Name Text 15 First name of patient

4 Surname Text 15 Surname of patient

5 Doc ID Number longinteger

Doctor ID

6 DOB date /time Short date date of birth

7 Gender Number Integer Male / female etc.

8 Date on list date /time Short date Date put on list

9 No children Number Integer Number of children

10 Addrs title Text 20 Name of house

11 Addrs stname

Text 20 Name of st

12 Addrs st no Text 20 Number of st. Notecould be 2a etc.

13 city Text 10 Name of city

14 PostcodeA Text 4 First part of post code

15 PostcodeB Text 4 Second part of postcode

Page 4: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 4

4. Starting Access

Exercise:

Call up Access by clicking the left mouse button on the relevant icon on the screen (i.e. thedesktop).

5. Getting help when in Access

The easiest way to find out about Access is to view the Help -> Contents and Index. This provides theindex to the help system, but unfortunately, this often gets you into hidden depths without giving you thebasic information you were originally looking for! The following exercise gives you a starting point.

Exercise:

First you need to close the initial window that appears whenyou open Access. Do this by clicking on the Cancel button.

From the Access main window choose the menuoption help -> Contents and Index.

Find the topic ‘Introduction to Microsoft Access 97’.Double click it to expand the options to give you what isshown opposite:

Page 5: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 5

Click on the option, Databases: What they are and how they work. Then click the display button.

You will now be presented with thefirst of 7 screens of information.

You can move between thescreens by clicking on the numbersin the top left hand of the window.

To return to the screen from whichyou came click the Help Topicsbutton at the top left hand part ofthe window.

When you have had enough move back to the helpcontents window, shown below. Now choose theoption tables

Read through the following topics:

• Tables

• Forms

• Queries

• Reports

Then close the help window.

Another way of obtaining help is to use the Officeassistant that is part of help. This has replaced theclue cards found in earlier versions. You get to the Office assistant by choosing the menu option Help �Microsoft Office Help.

Using Access97 help Exercise:

Once you have read the help screens suggested above answer the following. Feel free to go back aroundagain if you need to.

1. What are the four main objects or things in Access?2. What are the two views that Access offers for tables?3. Reports can be created from two sources of data. What are they?4. Queries produce two type of results. What are they?5. What is the main difference between the two types of datasets produced from a query?6. Forms allow you to create colourful screens to edit data in your database. What are the two standard

sources of data for a form?7. What are the two types of view for a form?

Answers are given at the back of this handout.

Page 6: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 6

6. How to create a Database in ACCESS

Key point:

The exercises in this session are based on developing a consultations database to collect dataabout consultations from a doctors perspective.

If you are not in Access call it up by choosing the relevant icon or menu option. Once Access has beencalled up you will be presented with thefollowing screen:

Choose the option Blank Database.

Alternatively if you do not have thiswindow displayed choose the menuoption File -> New Database. Thenclick the OK button.

Another dialogue box with the title’File new database’ now appears.

Ensure you have a formatted floppy disk in the external disk drive.

Make sure you have changedthe drives option to A: either bytyping it in or choosing from thedrop down list box presentedwhen you click the down arrowbeside it.

Type in the filename box:Cons1. This is short, in mymind for, consultations databaseattempt one.

NB there is no need for the full stop.

Click the Create button.

Access will now allow you to begin to set up your database called cons1 on your floppy disc. Notice thatthe message 'verifying system objects' appears momentarily at the bottom left hand corner of the screen(the status bar), This is often a good place to look for hints as to what's going on. All this message meansis that the computer is creating and saving a load of information about the database you have just createdwhich is called meta-data (the DBMS keeps its own record of tables, fields or the number of records ineach table etc.). You can check this information periodically by choosing the menu option File ->Database Properties.

Page 7: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 7

7. How to create a new table and fields in ACCESS

Once you have created a database you can start to create the tables. Unfortunately, you can't give a tablea name in Access until you have added one or more fields to it. We will therefore first add a field thensubsequently give the table a name in the exercise below.

You should have the database window displayed now (see below). This window provides an overview ofyour database. The options along the top, called tabs (table, query, from etc.) allow you to inspect thetables, forms and queries etc.associated with the database at yourleisure. At present your database isempty but by the end of the sessionyou will have several tables.

Exercise:

Make sure the tables tab is choseni.e. highlighted

Click the New button.

You will now be presented with thefollowing dialogue box:

The Table Wizards option in thedialogue box allows you to choosefrom a set of tables that have alreadybeen designed by Microsoft (themakers of Access). However at themoment we will develop ours fromscratch rather than borrow.

Exercise:

Select the 'Design View' option from the list (illustrated above) then click on the OK button.

The main screen for specifying the structure of a table now appears - at last. Note that the example onthe next page has some details in it whereas your dialogue will be blank.

Page 8: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 8

Top pane = Field list

Bottom pane =properties for each field

Press F6 to movebetween them or use themouse.

7.1 Adding fields

I have typed in the description for the first field in the above picture of the screen (screen shot). Follow theinstructions below to achieve the same result:

Exercise:

Type in the Field name Patient id.

Move to the data type column a down arrow appears. Click on it and a drop down selection listappears, choose the number type.

There are several types of numbers in Access. To indicate which one you intend to use moveto the bottom half (pane) of the dialogue box. Do this by pressing F6 (notice the status bar, atthe bottom of the screen gave you that information).

You should now have the field size field highlighted, again click the down arrow to choose thelong integer type. The picture below illustrates this step:

Tells you what’s going on

Page 9: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 9

You should have noticed several things when moving between the panels. The most important is that theinformation given in the right hand side of the bottom panel has changed to reflect the field you havecurrently highlighted. Its a bit like offering you automatic help.

Now add the description The unique patient identifier in the description column.

7.2 Saving your work

This is one of the most important things to remember to do constantly.

Exercise:

Save your work now by choosing the main menu option File � Save or click on the appropriatespeed button on the tool bar. To find out which speed button it is just leave the mouse cursorresting over each in turn. You will notice that after a few seconds a little text box appearsgiving you details.

When you attempt to save your work you will be prompted to give the table a name.

Give this table the name Patient. (Note no full stop or quote marks are needed)

A warning box will appear asking if you want a primary key choose the 'No' button. We willcreate one manually latter.

Another important thing you should learn is how to make backups of your work. Often discs fail, not onlythe floppy ones you carry around with you but also the, hard discs, found in machines. If you are doingsomething important:

ALWAYS KEEP THREE CURRENT BACKUPS OF YOUR WORK.

Page 10: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 10

Exercise:

Now please add the following fields to the patient table:

After adding each field save your work

Patient Table details

Field number

(for referenceonly)

Field Name Field type Field size Description

2 Title text 15 Mr, Miss, Ms, Dr or Prof.

3 First Name Text 15 First name of patient

4 Surname Text 15 Surname of patient

5 Doc ID Number longinteger

Doctor ID

6 DOB date /time Short date date of birth

7 Gender Number Integer Male / female etc.

8 Date on list date /time Short date Date put on list

9 No children Number Integer Number of children

10 Addrs title Text 20 Name of house

11 Addrs stname

Text 20 Name of st

12 Addrs st no Text 20 Number of st. Note could be 2aetc.

13 city Text 10 Name of city

14 PostcodeA Text 4 First part of post code

15 PostcodeB Text 4 Second part of post code

The first column 'field number' is just to help you keep tack of where your up to.

Make sure you have saved your work

You should now have 15 rows of field descriptions. In other words you have just created a table that has15 fields. Congratulations you have just created your first database and table.

Page 11: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 11

You should have noticed that the data dictionary presented at the beginning of this section and againabove has been used to create the table in ACCESS.

Key point:

The data dictionary forms the basis for the tables in ACCESS97

7.3 Input masks

One of the main bug bears of databases is the amount of crap data in them. One small thing you can doto help is make sure users are encouraged to enter only sensible data. Two common ways to do this is toallow them only the opportunity to enter data from a predefined list of options from a 'list box' of some typeor create a 'input mask'. We will create an input mask in this session.

The Input Mask property setting specifies how data is entered and displayed in the text box. We will setthis property for the DOB field you created in the last exercise to stop users entering duff dates of birth.

Exercise:

Select the DOB field by clicking on one of its cells or the left hand edge (get back to the fielddescription dialogue box we have been working in if necessary

Move to the bottom panel by mouse clicking or pressing F6.

Move to the Input Mask property in the bottom panel.

Click on the button beside it (the one with thethree dots; it is called a build button as itprovides instructions on how to build, in thisinstance, the mask). You will be presentedwith the input mask wizard dialogue boxpictured below:

If the short date (not the short time) is notalready chosen choose it then click next.Accept all the defaults until you come to thescreen where the next button is greyed (youcan't choose it) and click the finish button.

Save your work by choosing the main menuoption File � Save or click on the appropriate speed button on the tool bar.

The above process adds the 'Pattern' "99/99/00;0;_" to the input mask property of the field. Each of thesecharacters has a special meaning, which if you had known, you could have added without using thewizard. To find out what this has done exactly you need to try it out by moving from design view to datasheet view. This is described below. But first please carry out the following exercise.

Exercise:

Repeat what you have just done to the DOB field to the 'date on list' field.

Save your work by choosing the main menu option File � Save or click on the appropriatespeed button on the tool bar.

Page 12: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 12

7.4 Moving between design and datasheet view

Datasheet view allows you to try out the table you have designed. You can add, edit, search and deleterecords in datasheet view. Datasheet view is not really designed for you to change the structure of thetable which is best done in design view.

To move between datasheet and design view you:

Choose the menu options View ���� Design view or View ���� datasheet view alternatively use the followingspeed button:

Exercise:

Move to datasheet view. You should now have something like this on your screen. Think of isas a spreadsheet with each row representing a single record, and the columns the fields.

The darkened arrow near the top left hand corner indicates the current selected record. As we haven'tadded any to the table yet it is at record 1 of 1 look at the bottom of the window.

Exercise:

Click on the DOB field and notice what happens. Try typing in the invalid date 23/23/89. Whathappens?

Click the OK button to get rid of the error message.

Now delete the value by pressing the Esc key as you won't be able to move out of the cell untilyou do so!

Key point: Pressing the Esc key cancels any changes you may have made to a field.

Page 13: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 13

8. Working with records in datasheet view

If you have ever used a spreadsheet working in datasheet view it is pretty much the same with oneadditional rule to remember. The data you see on the screen is not actually saved to the database untilyou move off the particular record your working with.

Database

(Permanent)

Screen display

(Temporary)User

Only when you move off therecord or choose save record or

table from the menu

Key point:

To add a record to the actual database and not just the screen you need to move off the recordyou have been working on. This is achieved by either pressing the return key or clicking onanother cell above or below the record with the mouse or arrow keys.

Adding records Exercise:

Add the following two records to the patients table. Remember to move off the record to save itor choose the menu option File -> 'save record'

Field name: ID Title First name Surname Doc ID DOC1 Mr John Smith 100 01/01/682 Miss Sheila Jones 32 02/01/55

You should now have something similar to the picture below:

Page 14: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 14

8.1 Deleting records

Exercise demonstrating how to delete a record:

Make sure you are in datasheet view

Choose one of the fields in the record you want to delete. For this exercise you are going todelete record 2, Miss Sheila Jones that is the second record in the two pictured above.Therefore make sure the cursor is in one of the fields for her record.

Menu option Edit -> delete record

You will then be presented with a warning message, click the 'Yes' button.

Now save the changes by choosing the 'save table' menu item.

Note: There is an alternative shortcut to deleting a record, highlight the entire record by clickingon the left hand side of the table and pressing the delete key. You can also select severaladjacent records using this method.

9. Inserting / deleting or moving field definitions

This is for reference only:

You can insert or delete field definitions (rows in the table design window) by clicking on the above speedbuttons.

To move a field definition (row) you simply click on it and drag it, or copy and paste it. If you use the Copyand paste method you must rename the copy or delete the original. If you don’t you will get an errormessage when you try to save the table. This is because all fields in a table must have unique names.Also field names can only consist of what are called legal characters these are almost anything, except aperiod (.), an exclamation mark (!), a backquote character (`), and brackets ([ ]). To find out more look inthe Access help under the entry for standard naming conventions.

Key point: Fields in a particular table must be uniquely named and the name must consist oflegal characters.

Insert row(field) Delete row

(field)

Page 15: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 15

10. Required field values

A particular field in a record may be left blank. If that is the case the DBMS inserts an unseen value into itcalled a Null. Often it is sensible to ensure that people are forced to enter a value in a particular field.This can be achieved many ways but the most common is to set the required property of the field to yes.

Adding the required value option to a field Exercise:

Make sure you are in design view.

Set the required property of the Patient ID field to yes.

Now save your work by choosing the main menu option File � Save or click on the appropriatespeed button on the tool bar.

A error box will appear stating 'Data integrity rules have been changed' ….etc. Click the 'yes'button.

Save your changes.

Page 16: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 16

11. Creating Key Fields in Access

The ‘database theory’ handout describes what a key field is. Basically a key is a field, or a combination ofthem, which possess a unique value for each record in a particular table. In this session we will create themost important type of key, a Primary key. Remember a primary key is something that uniquely identifiesa record such as a bank account or driving licence number.

11.1 Setting a Primary Key

You can do this by firstly selecting the field(s) you want to make the primary key then choosing the menuoption Edit � set primary key or use the speed button with the picture of the key on it.

We now need to set the primary key for the Patient table:

Exercise:

Make sure you are in the design view of the patient table. The design speed button shouldappear depressed along the toolbar.

Select the Patient ID field

Choose the menu option Edit � primary key or use the speed button with the key on it.

A little key sign should appear beside the field details.

Now save your work by choosing the main menu option File � save orClick on the appropriate speed button on the tool bar.

11.2 Removing a primary key

The following is for reference only:

Made sure you have the table design window open and selected. You do not need to select any particularfield.

Menu option View � Indexes. Then remove whichever ones you want to by selecting the required rows.

Page 17: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 17

12. Closing an existing database

The final two tasks for this session will be to close and open an existing database. That is the one youhave been working on.

Be fore closing a database you shouls always save any changes you have made first and then click theclose symbol on the window that you have been working in. You will eventually end up with the Databasewindow, that is the one providing a description of what the current database contains in terms of tables,forms etc. Section 7 has a picture of the window. Then from the main access window choose File � closedatabase. You should now have a relatively empty window on your screen. To close down Access yousimply choose the menu option File � exit or click the close symbol on the window.

Exercise:

Close the cons1 database you have been working on BUT make sure you have saved yourwork first!

Close down Access.

13. Opening an existing database

To open an existing database you first open up Access. See section 1.4.

Choose the Open Existing Database option from the ‘Microsoft Access’ window. Section 1.6 gives apicture of it. You can either then choose from the list of databases or choose the ‘More files…’ option togive you the standard open dialogue box shown below. Set the drive and filename to the one you want.Make sure you choose the appropriate 'look in' folder (i.e. A: if you are working from the floppydisk).

Page 18: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 18

14. Consultations Exercise (creating the Con1 database)

So far we have only created one table containing data relating to patients yet the database is meant toprovide consultation details. We therefore also need to collect data about the doctor, the actualconsultation (which we will call an episode) and details of any possible diagnosis (we have assumed amaximum of four in the exercise). The exercise below asks you to add these tables. We will discuss howwe came about dividing the data up into these tables in the part of the course concerned with objectmodelling latter on just please accept it for now.

Exercise:

Please create the following tables and indexes to develop the cons1 database so that it will,when you have finished, consist of 6 tables.

Notes:An asterisk (*) after one or more field names in a table indicates that it is the Primary key of thetable.Remember to make key fields have the non-null property.Remember to save your work regularly.

Table Name: Doctor

Field number(for reference

only)

Field Name Field type Field size Description

1 Doc ID* Number Long Integer Unique ID for doctor

2 Doc first name text 15 First name of doctor

3 Doc Surname text 15 Surname of doctor

4 Gender Number Integer Male / female etc.

5 Date reg date Short date Date qualified

6 Addrs title Text 20 name of house/practice

7 Addrs st name Text 20 name of st

8 Addrs st no Text 20 number of st. Note couldbe 2a etc.

9 city Text 10 name of city

10 PostcodeA Text 4 first part of post code

11 PostcodeB Text 4 second part of post code

12 Phone No. Text 15 Note: Need to decideformatting

Page 19: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 19

Table Name: Episode

Field number

(for referenceonly)

Field Name Field type Field size Description

1 Episode ID* Number Long Integer Unique ID for episode

2 Patient ID Number Long Integer

3 Doc ID Number Long Integer

4 Date Seen date Short date Date seen

5 Urgency yes/no n/a Whether they were anemergency or not

6 Systolic Number integer

7 Diastolic Number integer

The next three tables provide information about diagnosis. Notice the compound keys:

Table Name: PRIM_D

Field number

(for referenceonly)

Field Name Field type Fieldsize

Description

1 Episode ID* Number LongInteger

Episode this relates to

2 Primary* Text 20 primary diagnosis

Table Name: SEC_D

Field number

(for referenceonly)

Field Name Field type Fieldsize

Description

1 Episode ID* Number LongInteger

Episode this relates to

2 Secondary* Text 20 secondary diagnosis

Page 20: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 20

Table Name: OTHER_D

Field number

(for referenceonly)

Field Name Field type Fieldsize

Comments

1 Episode ID* Number LongInteger

Episode this relates to

2 Other* Text 20 Any other diagnosis

Make sure you have saved your work.

During the next session we will be linking these tables together, and creating several nice input screensthat are easier to use than the datasheet view of the table.

15. Resumé

You have now learnt the basics of constructing tables and fields. You have also learnt how to set a varietyof characteristics for fields including, input masks, required values as well as the very important process ofsetting up primary keys.

16. Check what you have learnt

Now go back to the beginning of the material for the session and read through the 'Learning outcomescheck list' for the session. How many can you tick? If you are not sure about any particular ones go backthrough the exercise. If you are still unsure please contact me.

Page 21: Introduction to Access97 (1) - · PDF fileIntroduction to Access97 (1): Tables & Fields by Robin Beaumont e-mail: robin@robinbt2.free-online.co.uk 1. ... 5 Doc ID Number long integer

Introduction to Health InformaticsAccess97 (1) - Tables and Fields

Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected] Source: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOC Page 21

17. Renaming or copying tables

The details are given below for reference:

You can rename a table when the database window is displayed and selected along with a table name.The database window has been shown at the beginning of the section 'How to create a new table andfields in Access' You choose the main menu option File � Rename. You will then be prompted for a newname.

You can copy a table, from the currently open database when the database window is displayed andselected along with a table name. Choose the main menu option edit � copy. Then the main menuoption Edit � Paste You will then be prompted for details as to what exactly you want to copy either thestructure and / or the records. See the diagram at beginning of 'How to create a new table and fields inAccess' section to find out what the 'database window' is. You can also import a table from anotherdatabase by right mouse clicking when the tables tab is selected and choosing the import menu item.

18. ReferencesAccess online help.

Access manuals.

Reingruber Michael C. Gregory William W 1994 The Data Modeling Handbook John Wiley & Sons.Chichester.

19. Answers to exercises

These are the answers to the exercises on page 6.

1 Tables, Queries, Forms and Reports.2 Design and datasheet (working and design model.3 Tables and Queries.4 Dynasets and snapshots.5 Dynasets you can edit. Snapshots you can’t edit.6 Table or Query.7 Design and form view (working and design mode).

Document info:Robin Beaumont 29/03/00 Tel:0191 2731150 e-mail: [email protected]: Laptop; C:\HIcourseweb new\chap8\s1\ACCESS1ver7.DOCDate: 29/03/2000 16:54