Introduction to Microsoft Access                                 Part 1 - TablesTables are a fundamental requirement of an...
6. The Wizard then tells you what tables there will be in your database and whatFields each table will contain. You can ti...
13. You will see that an Access Database consists of Tables, Queries, Forms,Reports, Macros and Modules, all of which are ...
6. Choose a personal table and select all the fields from the Recording Artists sampletable. Your screen should look like ...
3. Understanding Your New Table1. First, let us try to understand what the Wizard did. You now have one table in yourdatab...
4. Creating a Table Without the Wizard1. Now you should try to create a table without any wizard help at all. To do this, ...
4. Close the table design view and name the table Albums.5. Re-open the Artists table in Datasheet View. Try adding a reco...
5. Access has 22 button bars, which change depending on what you’re doing. Thereare so many buttons that nobody could ever...
6. Data TypesYou have now created four tables and you have set a data type for each field that youhave created. You have a...
7. Flat File or Relational?A Flat File database contains a single table. Flat File Databases are very easy tocreate and us...
8. Build Relationships for the Music Database1. Click the Relationships button on the toolbar or select Relationships from...
9. Index Your FieldsYou will now return to the Table Design view to “tweak” your tables for greaterefficiency. The first t...
10. FormatsStaying in the Field Properties, we will now check to see if a Data Format isappropriate.You use a format if yo...
11. Input MasksThe aim of an Input Mask is to prevent the user entering bad data. The great dangerin using them is that yo...
12. Validation and Required FieldsTogether with Input Masks, validation tests and required fields are your weapons inthe w...
To write a validation rule, you can either write the rule yourself, or you can use theExpression Builder. To start the Exp...
13. Keyboard ShortcutsF2              Select an entire fieldCtrl+;          Insert the Current DateCtrl+:          Insert ...
Page 18 of 18   7/4/2012
Upcoming SlideShare
Loading in …5
×

Access1

265 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
265
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Access1

  1. 1. Introduction to Microsoft Access Part 1 - TablesTables are a fundamental requirement of any database. To get valuable information from a database, you first have to have data. All your data will be stored in tables.1. Creating a Relational Database in 30 Seconds!1. Start up Access2. Use the Database Wizard3. Select the Music Collection wizard4. Save the database file in your My Work folder5. The Wizard starts. Click Next.Page 1 of 18 7/4/2012
  2. 2. 6. The Wizard then tells you what tables there will be in your database and whatFields each table will contain. You can tick or un-tick any field to customise yourdatabase. Click Next when done.7. You then get to select a colour scheme. Click Next when you’re happy.8. You will then be asked to choose a report style and finally you will be invited toname the database. Click Finish when you have answered all the questions in theWizard. The database will then be created.Your database is now created and, as promised, the whole process should have takenno more than 30 seconds. We will now take a tour of the database window.9. You are presented with a Switchboard window. This is an interface, which can becreated to make the database user-friendly.10. Click the Enter/View Recordings button. The Recordings Form is opened.Try entering details of some of your favourite albums.11. Close the Recordings Form and close down the Switchboard (click the cross inthe top-right corner of a window to close it down).12. Although you have closed the Switchboard, the database is still open. Double-click the Music Collection Database window, which is currently minimised in thebottom-left of the Access window.Page 2 of 18 7/4/2012
  3. 3. 13. You will see that an Access Database consists of Tables, Queries, Forms,Reports, Macros and Modules, all of which are stored in the Database Window asseparate objects. If you take a tour of this window, you should see that the wizard hascreated tables, forms and reports in the music collection database. You can double-click each object to open it. Some of the forms should be familiar to you because youhave previously opened them via the Switchboard.14. If you open the Tables, you should see that the only data in the database, is thesample data you entered into the Recordings Form. Although you entered this datain the Recordings Form, you should see that this data is being stored in several tables.The form was created to provide an easy interface for the user to enter the data.You should, by now, realise that data entry forms and switchboard forms are providedfor the convenience of the user. As a database designer, you will want to make yourdatabase very easy to use. You will also see that good database design can ensure thatthe data entered is accurate. --------------------------------2. Start with a Blank DatabaseUnfortunately, you won’t learn how to be a database designer by using the DatabaseWizard! Now is the time to create a database from scratch.1. Click on File and New Database.2. Create a New Database using the Blank Database.3. Give your database a Filename.4. You should now have a blank database Window open at the Tables tab. Click Newto create a new table and select Table Wizard.5. Click OK and you should see a screen, which gives you a wide choice of sampletables and fields for business and personal use.Page 3 of 18 7/4/2012
  4. 4. 6. Choose a personal table and select all the fields from the Recording Artists sampletable. Your screen should look like this:7. Allow the Wizard to set a Primary Key and change the selection on the last screen,so that you are going to modify the table’s design after the wizard is finished. Youshould finish with a screen that looks something like this:It is worth studying this screen for a while. You should see that the Wizard has setthe Fields, including RecordingArtistID, which is a Primary Key. You should seethat each field has a Data Type (e.g. Text, Number, Date/Time) and they also haveField Properties, which includes a Field Size setting.8. Close the Table’s Design View and you will see that the Recording Artists table isnow shown in the database window. Click the Right Mouse Button on the table andselect Rename. Change the name to Artists.Page 4 of 18 7/4/2012
  5. 5. 3. Understanding Your New Table1. First, let us try to understand what the Wizard did. You now have one table in yourdatabase (called Artists). If you open this table in Datasheet View you can startentering data into it.You might notice several things: • The RecordingArtistID field assigns a unique number to each record that you enter. • The Birth Date field only allows you to enter valid dates. Try entering an invalid date (e.g. 45/13/02). The birth dates entered above are made up. Try using the Internet to research the real D.O.B.s for your favourite artists. • You can write as much as you want in the Notes field. It would be a good idea to adjust the width and height of the columns (as above).2. Once you have entered several records, you can try to search your table. To dothis, click in the column in which you wish to search and press CTRL+F (or selectFind from the Edit menu). Perform a few simple searches using this method.3. If you don’t understand these terms already, it is high time that you learnt thejargon:Data Stuff you put into your databaseFields A place for your data to live e.g. a database of footballers would have fields such as FirstName, LastName, Position, Team etc.Records A record groups data together in an order If it wasn’t for records, your database wouldn’t know which last name went with which first name.Table A collection of records that describe similar data In a flat-file database, all the data goes into a single table. However, Access is a “relational” database, meaning that you can create many tables and link them together.Database File A collection of tables and also various other tools to assist in the use of the data e.g. queries, forms, reports Everything is compressed together in a single file with an MDB extensionPage 5 of 18 7/4/2012
  6. 6. 4. Creating a Table Without the Wizard1. Now you should try to create a table without any wizard help at all. To do this, youcreate a new table in Design View.You are presented again with the Table Design View screen but, this time, no fieldshave been created for you.2. Enter the fields as follows:N.B. Make sure you do the following: • Make RecordingID a Primary Key (click the Right Mouse Button in the grey area next to the field name) • Make sure the correct Data Type is set for each field (these will be explained later) • The only field size you have to set is for the Title and Label fields. Select a suitable size (a little larger than you think you will need). • Leave no spaces between field names • Enter a description for each fieldFor Discussion • Why should field sizes not be too big? • Why should field sizes not be too small? • How can you enter a Default Value for a field and what is the purpose of doing this? • Why shouldn’t you put spaces in field names? • Why bother entering a description? • What is the purpose of a Primary Key? • Can a table have more than one Primary Key?Page 6 of 18 7/4/2012
  7. 7. 4. Close the table design view and name the table Albums.5. Re-open the Artists table in Datasheet View. Try adding a record. Then trydeleting an existing record.6. Create a new table called Tracks with the following fields: TrackID (Primary Key, AutoNumber) RecordingID (Number) TrackNumber (Number)7. Create a fourth table called Categories, as follows: CategoryID (Primary Key, AutoNumber) Category (Text) --------------------------------5. Help and Helplessness1. You can press F1 for Help, at any time (try it)2. The Office Assistant is now always as helpful as he could be. To get real help,look in the Help Menu:3. Select Contents and Index to see the full Help system. The Index tab gives you afull alphabetical index of help topics. The Find tab, allows you to search for a topicto get help on.4. The What’s This? Feature is particularly useful. Select this item from the Helpmenu and your cursor will change to an arrow with a question mark beside it. Youwill get help on the first thing you click on. You can ask Access “What’s This?” atany time. Try selecting What’s This and clicking on the Design button of the TableWindow:Page 7 of 18 7/4/2012
  8. 8. 5. Access has 22 button bars, which change depending on what you’re doing. Thereare so many buttons that nobody could ever hope to remember what they all do. Tomake life easier for you, there are Screen Tips, which pop up when you hold themouse button over a button (try it).6. Get into the habit of using the Right MouseButton. In Access, when you click on something,it invariably brings up a menu. For example, tryclicking the Right Mouse Button on one of yourtables. You can see that you now have optionssuch as renaming, printing or deleting the table.You can also open the table in Design or Datasheetview from this menu.7. Saving your work in Access is very easy. Access Autosaves most things (forexample, each record is saved as soon as it is created). This is a benefit but also adanger because, for example, if you delete something by accident, Access will notquestion your decision! Pressing Ctrl+Z or select Undo from the Edit menu willusually undo the very last thing you did but don’t rely on this to get you out oftrouble.8. Backup is essential and also very easy. Access saves all your tables, queries,reports etc. in one handy file with an MDB extension. Your early databases willeasily fit on a floppy disk:Page 8 of 18 7/4/2012
  9. 9. 6. Data TypesYou have now created four tables and you have set a data type for each field that youhave created. You have also tried entering data into the tables and you have noticedthat certain fields will not allow certain types of data. For example, you can’t enter aninvalid date into a date field. You can’t enter text into a number field.In your tables, try to find examples of each of these data types (you will find most butnot all). Why have the data types been set in this way?AutoNumber Automatically generates a number each time you add a record. This number is used as a unique identifier for each record.Text Stores letters, numbers and any combination thereof. Can be up to 255 characters in lengthMemo This is a really big text field. Holds up to 64,000 characters (about 18 pages of text).Number Holds numbers and decimal points but nothing else. Set a field to Number if you want to do calculations.Currency Formats money fields.Date/Time Either the date or the time or both, in a variety of formatsYes/No For fields where one of two answers is required. You can have Yes/No, True/False or On/Off. It is possible to add your own variants.OLE Object You can add photographs, sounds etc. in a field of this data typeHyperlink For webpage addressesLookup Wizard Prevent errors by presenting the user with a list of acceptable answers to choose from.For Discussion • Why are telephone number fields usually set to text? • How does setting the right data type help prevent bad data being entered? • You can enter numbers into a text field. Apart from the fact that it guards against bad data, why should anyone want to bother creating a number field? • Why not set all text fields to Memo?Page 9 of 18 7/4/2012
  10. 10. 7. Flat File or Relational?A Flat File database contains a single table. Flat File Databases are very easy tocreate and use. They are ideal for simple things like databases of address books,video collections, and so on. They are similar to the traditional desktop “card-file”.Relational databases have multiple tables that are linked together with “key fields”.Relational databases really shine when they are used to solve big business problems.A whole business can use one database that integrates the whole organisation.You need to understand why flat file databases are inadequate for big tasks.This is a simple database for a library:There are three tables – Books, Borrowers and Loans. When the library gets a newbook, it enters its details into the Books table. All the members of the library havetheir details entered into the Borrowers table. When someone borrows a book, theLoan table is used. The information about the book and the borrower does not have tobe entered each time a loan is made because this information is taken from the Bookand Borrower tables. This is indicated by the lines that link the tables together. Theselinks are known as relationships.The symbols at each end of the line indicate what type of relationship exists:One to One: Each book can only be borrowed onceOne to Many: One borrower may borrow many booksYour TaskImagine that you have to set up a database for a library but you only have a flat filedatabase application. • Design the table that you will use and describe how the system will work. • List all the problems you encounter • Write a report to the library committee telling them why they ought to invest in a relational database system, such as Access.Page 10 of 18 7/4/2012
  11. 11. 8. Build Relationships for the Music Database1. Click the Relationships button on the toolbar or select Relationships from theTools menu.2. The Show Table window will ask you which tables you want to display in theRelationships Window. Select all four of your tables and then close the Show Tablewindow.3. You can adjust the size and the position of the four tables in the RelationshipsWindow.4. To build a relationship between fields, click on a field with the Left Mouse Buttonand drag it onto the field you want to link to. A window appears asking you toconfirm the relationship. Here, you also have the chance to change the type ofrelationship.Things to watch out for: • Linked fields must be identical (same data type, same size, same name) • Select Enforce Referential Integrity and Cascade Update Related Fields if you want to update corresponding values in a related table when the primary key value is changed.Your TaskYou have to create relationships for your tables to reflect the following facts: • One album has many tracks • One artist may have recorded several albums • There may be several albums in the same musical categoryWhen you have finished, you should have something like this:If the symbols at the ends of the relationship lines don’t match, try changing your joinsettings. To edit a relationship, double-click on a join line. To delete a relationship,click the line once and press the Delete key. Close the Relationships Window whenyou’re finished.Page 11 of 18 7/4/2012
  12. 12. 9. Index Your FieldsYou will now return to the Table Design view to “tweak” your tables for greaterefficiency. The first thing to do is to index some of your fields.The purpose of indexing your fields is to speed up sorts and queries. You should notindex every field because too many indexed fields slows down data entry.You have to index each of your fields in turn. To do so, select a field and click theIndex section of the Field Properties.Your three options are:No Don’t index the fieldYes (DuplicatesOK) Most of the time you want to allow duplicate records.Yes (No Duplicates) Key fields should be set to No Duplicates because a key field must be unique. You don’t want two customers with the same customer number.You can see a list of indexed fields by clicking the Indexes button on the toolbar.For DiscussionYou should set the Index to No Duplicates when the records have to be unique (forexample, a key field must be unique.What other fields could be set to No Duplicates?Page 12 of 18 7/4/2012
  13. 13. 10. FormatsStaying in the Field Properties, we will now check to see if a Data Format isappropriate.You use a format if you want to change the way your data appears on screen.Each field type has its own set of formats. Some of the most commonly used are asfollows:Text and Memo FormatsSymbol Meaning What it Does > Greater than Makes all text appear in upper case < Less than Makes all text appear in lower caseNumber and Currency FormatsGeneral Number Default optionCurrency Displays numbers as currencyFixed Locks the field to display a specified number of decimal placesStandard Adds a thousands separatorPercent Displays decimal places as a percentageIn a number field, you can change the Field Size setting from Long Integer to Singleif you want to dispense with decimal places. However, if the field is part of arelationship, you should be aware that an AutoNumber field must be set to LongInteger.Date/Time FormatsYou have a choice of how the date/time is displayedYes/No FormatsYou have three initial choices, which are Yes/No, True/False and On/Off. You canadd your own selections to this list.Page 13 of 18 7/4/2012
  14. 14. 11. Input MasksThe aim of an Input Mask is to prevent the user entering bad data. The great dangerin using them is that you might end up preventing the user from entering correct data.For this reason, you must think carefully before deciding to set an input mask for afield.An input mask is a series of characters, which tells Access what kind of data toexpect. Each field can have an input mask, with the exception of a memo field.Input Masks work best with highly consistent data, such as phone numbers, nationalinsurance numbers and postal codes.You can either write your own input mask or you can use the Wizard. To use theWizard, click the Build button, which appears when you click the Input MaskProperty.Your TaskCreate an Input Mask for a telephone number and then test it. Try entering a varietyof valid postal codes and make sure they are accepted. Try international and mobiletelephone numbers.For DiscussionWould the telephone number field be better off not having an input mask?Page 14 of 18 7/4/2012
  15. 15. 12. Validation and Required FieldsTogether with Input Masks, validation tests and required fields are your weapons inthe war against bad data.Using the Required property is easy because there are only two choices – yes and no.Set the Required property to Yes if you want to force the user to enter something inthis field.For DiscussionWhen would you want to set a Required property to Yes?What would happen if you set all fields to Required?The Validation property is more sophisticated because it performs a test on incomingdata to make sure it’s what you want.Two properties require your attention:Validation Rule The test that will be applied to the dataValidation Text This is a message, which Access will display if the data is unacceptable (i.e. if it fails the validation test).Validations work best with number, currency and date fields because the incomingdata is more predictable. The Validation Rule is written as an Expression.An Expression is an instruction that you give to Access in a language that Access canunderstand. For example, if you want to force users to enter only positive numbers ina number field, the expression is “> 0” i.e. the number must be greater than zero.Try some of these expressions on some of your fields and see what happens. Mix andmatch the operators and see what you can come up with:>0 Must be greater than zero<> 0 Cannot be zero>= 5 Greater than or equal to 5>= 0 And <= 100 Must be between 0 and 100 (inclusive)<= 0 Or <= 100 Must be less than 0 or greater than 100 (inclusive)>= Date ( ) Must be today’s date or later>= Date ( ) Or Is Null Must be today’s date or later or blank>= #1/1/96# And <#1/1/97# Must be a date in 1996Like "A????" Entry must contain 5 characters and start with the letter APage 15 of 18 7/4/2012
  16. 16. To write a validation rule, you can either write the rule yourself, or you can use theExpression Builder. To start the Expression Builder, click the Build button thatappears when you select the Validation Rule Property.The Expression Builder helps you to write expressions. It lists functions andoperators that you can use. It can also prompt you to remind you what to do next andit will stop you making common mistakes.Your Task1. Write an Validation Rule and Validation Text to apply the following tests: • Must be earlier than today’s date • Must be between January 1st 1990 and today’s dateFor Discussion1. What would happen if you set these validation rules: <= 0 >= 1002. Why would you probably not want to set a validation rule for a text field?Page 16 of 18 7/4/2012
  17. 17. 13. Keyboard ShortcutsF2 Select an entire fieldCtrl+; Insert the Current DateCtrl+: Insert the Current TimeCtrl+Enter Insert a Line Break (use it in a memo or large text field)Ctrl++ Add New RecordCtrl+- Delete the Current RecordShift+Enter Save the RecordCtrl+Z Undo the last change you made (dont rely on this)Ctrl+Enter Open the selected object in Design ViewAlt+F4 Quit Access14. Summary (from the Access Help file)Page 17 of 18 7/4/2012
  18. 18. Page 18 of 18 7/4/2012

×