Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Contents
ContentsScenario.............................................................................................................................................3Task 1 – Setting Up a Database...............................................................................................4
Creating a Table.........................................................................................................................4Adding Fields...............................................................................................................................8Data Types...................................................................................................................................9Validation....................................................................................................................................11Forms............................................................................................................................................16
Scenario
The number of unsolved petty crimes in the area of Castelldefels
and Sitges are on the rise. The police are struggling to find out who
has committed them and have brought in a new detective –
Sherlock Holmes.
Sherlock Holmes has come up with the ingenious idea that if the
police had a database of all the suspects then it will allow them to
crack all the unsolved cases. He has employed you (the greatest
technical expert in the whole of South Yorkshire) to create the
database and help him solve the cases.
Task 1 – Setting Up a Database
Before we can start helping Detective Sherlock Holmes, we first need to set up a database to store all of the suspects’ details. Follow the print screens shown below to help create your database.
Creating a Table
1. Open up Microsoft Access.
2. Select Blank desktop database.
3. Type in the name of your database e.g. Suspect Database
4. Click on the folder icon at the end of the File Name.
5. Find your own database folder. If you do not have one, then create one. Then click OK.
6. Click on “Create”
7. This will give you a table which looks like this. You now need to click on “View” to be able to start adding fields.
8. Once you have clicked “View” it will ask you to name the table. Call it Suspect Table and then click “OK”.
9. This then gives you the basic table view like the one shown below.
Adding Fields
The next step in creating our database is to add all the necessary fields which we will use. A field is a single piece of data about one person or one thing e.g. age, height etc.
1. Type out all the field names like the ones shown below:
Data Types
Most of the fields that you have will use the Data type short text. Access defaults most fields to short text. The main exception is the ID which is set to AutoNumber. This is done so that we do not have
records with the same identity number. Not all of the other Field Names should be set to text.
1. For example “Age” should not be set as text as the information which will be put in that field is going to be a number. To change this you need to click into the ‘Data Type column next to ‘Age”. An arrow should appear with a pick list. Choose the right data type for this field.
2. Access automatically gives each ‘Short Text’ data type field a maximum number of 255 characters that can be entered. However, most of your fields won’t need that much space. Sex is usually
‘male’ or female’, so this field really only needs a maximum of 6 spaces allowed.
Click into the field called ‘Sex’ and look at the field size at the bottom on the screen. Click into the ‘field size’ where it has defaulted to 255 characters and change it to 6.
The reason that we do this is because if you allow every single ‘Sex’ field to store 249 wasted characters, and the same with all of your other fields, the database would become very large.
Have a look through the rest of your fields and see if you can reduce the number of characters assigned to them. If you are unsure then leave it at 255 characters.
Validation
You are going to put some validation into your database. Validation tries to stop you entering data that shouldn’t be allowed or it can try to make sure that you don’t forget to enter data into important fields.
Because we are making a database to store suspect details we need to make sure that the “First Name” and “Surname” are definitely entered so that we know who to arrest for the different crimes. To do this we need to make sure that those fields show as “required”.
1. Click on the “First Name” field and look at the field properties at the bottom.
2. Look for ‘Required’ – at the moment it defaults to ‘no’.
3. Click into ‘Required’ and an arrow will appear. Choose ‘Yes’.
Now, you cannot leave this field blank when you come to enter data.
4. Repeat the same steps for the “Surname” field.
We are going to put some more validation into the database to try to stop mistakes being made when entering data.
You have a field called ‘Sex’. You may have set this to a field size of 2 so that you can enter ‘M’ or ‘F’ or you may have set it to 6 so that you can enter ‘Male’ or ‘Female’ – either way is fine.
You want to make sure that people can only enter either M or F, or Male or Female. It would not make any sense if they could enter ‘S’ or ‘Cat’! We are going to set up some validation to make sure that they can only enter the right information.
5. Click into the field called ‘Sex’ and look at the field properties at the bottom.
6. Click into ‘Validation Rule’ and depending on how you set your database up, type either: M or F OR Male or Female (you don’t need to put in the speech marks; Access will do that for you).
Access will now not let anyone put in incorrect data e.g. Car.
It might be useful to also create an error message so that if someone does put in the wrong data by accident, they will be shown an error message and told what they should enter.
Click into the box called ‘Validation Text’ and write what the message that you would like to appear, like the example shown below:
7. Some things you will find that you type in over and over again. This is a pain as it takes a lot of time to do, and there is the risk that one time you might make a mistake and enter ‘Brwn’ instead of ‘Brown’. To stop this error from occurring we are going to create a list of values which people can select from.
Click into the data type area of the “Hair” field and choose “look up wizard” from the drop down menu.
This box will then appear.
8. Choose I will type on the values that I want and click next. 9. Type in the following list of values. Check you have spelt them
correctly and then click on next and then finish.
10. To put the table back into normal view, click the following:
11. When asked click Yes to saving the table. Forms
We now need to set up a form so that people can enter suspect’s details into our database.
1. To set up a form you firstly need to click on “Create” and then click on “Form Wizard” icon.
2. This box will then appear.
3. Click on the >> arrows to put all of the data from the ‘available fields’ into ‘selected fields’
4. You can then click on “Finish”
5. This box will then appear:
You have now set up a simple database and can begin entering your suspect’s details.