Upcoming SlideShare
×

# MS Access 2007

16,231 views

Published on

This file contains the basic information about MS Access 2007, what is its purpose of usage, how to use it and some examples of simple databases.

Published in: Education, Technology
9 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Thank You...

Are you sure you want to  Yes  No
• Well done

Are you sure you want to  Yes  No
Views
Total views
16,231
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
832
2
Likes
9
Embeds 0
No embeds

No notes for slide

### MS Access 2007

2. 2. MS Access vs MS Excel  MS Excel  Spreadsheet  Flat database  all information has a one-to-one relationship  MS Access  like multiple spreadsheets that are connected to one another  one-to-many relationships  many-to-many relationships  Examples  Printed Phone Directory (White Pages)  Flat Database: one-to-one relationships  Library Catalog  Relational Database: Many-to-many relationships ** Library patrons check out many books ** Books are checked out by many patrons  University Class Schedules  Students have many professors.  Professors have many students  Classes can be held in many classrooms
4. 4. Exercise #1 Exercise #2 1. Name both tables. 2. Establish a primary key for each table. 3. Create a relationship between the two tables. 4. Set appropriate properties for all fields. 5. Enter at least five mock student records in Table One. In Table Two, enter at least three courses for each students listed in Table One. 6. The tables must contain the following information: Table 1 Table 2 Student ID Student ID First name Course Last name Letter grade Gender Phone number Address Major Minor
5. 5. 7. Create a report containing ID numbers, first names, last names, courses, and letter grades for all students. 8. Create a query to search for students with all course grades above B. Display the ID number, first name, and last name in the query. Exercise #3 1. Create a new database, save it on the desktop and name it “School Database” 2. Create a Table in the School Database with the following: Field Name Data Type Field Size or Format ID Number Text 10 Name Text 15 Surname Text 15 Telephone Number Number Long Integer Date of Birth Date/Time Medium Date Stipend Currency Currency Foreigner Yes/No Yes/No 3. Make the “ID Number” Field as the Primary Key. 4. Save the table as “Student’s Table” 5. Return to the main Access window. 1. Open the “Students Table” and enter 5 complete records. 2. Sort the table in ascending order by surname 3. Move the Date of Birth and Telephone Number fields so that the Date of Birth field is now directly after the Surname field. 4. Delete the last Record you have entered 5. Change the field size of the Surname to 20 1. Create a Form with all fields on the Student’s Table. 2. Name the form Students Entries 3. Make the ID Number of Each student in the form, Red 4. Insert a Picture in the form in way that all text is visible. 1. Create a report based on the Student’s Table showing the Fields Name, Surname, and Telephone Number. 2. Name the report Telephone List 3. Insert a picture in the report Header 1. Create a query, showing all fields of those students who have a particular surname of your Choice. 2. Create another query showing all fields of those students born after 1987. 3. Create a query showing only the Student’s Name, Surname and Date of birth.
6. 6. Exercise #4 Create a Table 1. Create a table in Access that looks like the table below (Create tab > Table [in Tables group]). Figure 1 – Table Note: the ID field can be any unique number. When you’re entering data, the ID field automatically increments. a. Save the table as tblStudents. Note: To change the ID, go to Design View. In the Data Type field, change AutoNumber to Number, then Save (Go to View > Datasheet View > in ID column, manually type in 1, 2, etc., Save). 2. Create a query that displays the first name, last name and city of students from California (page 13 of this guide discusses queries) [Create > Query Design]. a. Save the query as qryCAStudents. 3. Create a form using the Form Wizard. Refer to page 16 if needed. [Create > More Forms in Forms group > Form Wizard). a. Use tblStudents to create the form. b. Include all the fields. c. Use the Columnar layout. d. Save (title) the form as frmStudents. 4. Create a report using the Report Wizard. Refer to page 17 if needed. [Create > Report Wizard in Reports group]. a. Use tblStudents to create the report. b. Include the following fields: • First Name • Last Name • ID Number • Class Standing c. Sort the records by Last Name. d. Save the report (title) as rptStudentSummary. 5. You should have the following tables created in the Shutter bar when you’re done with the exercises.
7. 7. Figure 2 - Tables Created Exercise #5 Record Entry with Properties 1. In the Database Window, double-click the STUDENTS table (this is a quick way to open a table in Datasheet View). 2. The student record you entered before will be displayed. Click in the Last Name field underneath Robbins. 3. Type Stevens for the Last Name and press [Enter]. 4. Type Sarah for the First Name and press [Enter]. As soon as you begin entering a date in the Date of Birth field, the Input Mask will appear. 5. We will test the Validation Rule by entering a date that’s not accepted. Enter a future date such as 020809 (remember you won’t need to enter the / since the input mask puts them in there for you). As soon as you press [Enter], the Validation Rule will recognise that the entry is invalid and the Validation Text will appear. 6. Click OK to clear the message. You won’t be able to proceed until you enter a valid date or press [Esc] to cancel the entry. Enter 100489 (10/04/89) for the date and press [Enter] to proceed to the next field. 7. Enter 24 Browne Ave for the Address Field and Yokine for the Suburb field. 8. Enter 6060 for the Postcode field (notice the input mask in this field). 9. Notice that the Default Value for the State field (WA) has already been entered. To test the Validation Rule, enter NY as the State. The Validation Text will tell you that only Australian states can be entered. 10. Type WA for the State and press [Enter] (The Input Mask used for this field automatically converts entered text to uppercase). 11. For the final four fields, enter the information shown below. Phone Gender Mark Comment (08)92498127 Female 62 New Student 12. Close the table when complete. 13. The new data will be saved automatically in the Database. Exercise #6 Data Entry Using a Form 1. From the Database Window, make sure the STUDENTS table is selected.
10. 10. 4. When you are finished, the table Contacts is now populated with three records. It should look something like this. 5. Now let‘s input some data in the Training Tasks table. 6. In the Navigation Pane double click the Training Tasks table to open it. Notice that it is an empty table. 7. Just like the previous table, enter the two records listed below. Again the ID field is the key field and does not need data entered. Just tab past it and an auto-number will be assigned. Save time when entering the Priority and Status fields by entering the data by using the pull-down arrow within the field instead of typing in these fields.
12. 12. 4. If you see a property sheet like the one above, it is not needed. You can close it by clicking the close (x) button to the right. This property sheet is used to set properties of each control on the report and is not needed at this point. 5. The form is currently in Layout view. It shows the actual printed page borders. 6. Save the Report by right-clicking the Training Tasks tab, then select save from the list. Use the default name Training Tasks, click OK. 7. Note, in the Reports section of the Navigation Bar you will see the Training Tasks report. 8. Open another report. Open the Contact Address Book report by double-clicking it the Navigation Bar within the report section. This is a pre-formatted report that shows only address information. You will notice that this report is alphabetized by last name with some nice formatting. This is a good example showing you some of the features with reports in Access. 9. Open another report. Open the Contact Phone List report by double-clicking it in the Navigation Bar within the report section. This is a pre-formatted report showing only contact phone numbers. Again, you will notice that the report is alphabetized. Both reports are based on the data from the Contacts Table. Exercise #8 PART I – THE FILE STRUCTURES Our database shall be to keep track of salespersons in a company. The SALESPERSON table shall be made up of the following fields: Field Name Data Type Width Other Info Salesperson ID Auto number Primary Key Last Name Text 12 char. First Name Text 10 char. SSN Text Text 11 char Input mask as SSN CommRate Number Single, 3 decimals Commission rate is entered as a percentage, thus 6.5% is entered as .065 Office Text 4 char. Upper case (> in Format). Validate as SAV or BRU or ATL or GRE or CHA State Text 2 char. Upper case (> in Format); Default value is GA CompanyCar Yes/No
14. 14. PART III – CREATE THE CUSTOMER TABLE 1. Now that you have created the Salesperson Table, and entered the data, you’re ready to create the Customer Table. 2. Following Steps 1 through 9 in PART II, create the Customer Table and enter the data, using the same steps for corresponding fields. 3. MAKE SURE THAT THE CUSTOMER RECORDS CONTAIN SALESPERSON ID#s WHICH EXIST IN THE SALESPERSON TABLE. 4. Enter about four records. PART IV – CREATE THE RELATIONSHIP 1. Exit your table after you’ve entered all the data. 2. Click on the Tools drop-down menu from the menu bar. Click on the Relationships command. 3. The Show Table dialog box is displayed: • Click on each table and then click on Add • Click on the common field in the Salesperson table, and drag it to the same common field in the Customer table. • When you do, the Relationships dialog box will be displayed. Confirm the fields displayed – and their tables. Then click in the Enforce Referential Integrity check box. • Click on the Create button. The relationship has been created. 4. X out of “Relationships.” If asked to save it, click "Yes." PART V – CREATE THE REPORT USING THE REPORT WIZARD 1. Click the “Report” tab. Click New. 2. Click the Report Wizard. Then click on the drop-down arrow to choose the table to Report from. Choose the Salesperson table. 3. Click on the fields you wish to report, and then the right arrow, to place the field in the “Selected Fields” box. To place ALL the fields in the box, click the double-arrow. 4. After you’ve done this, if you want to remove a field, click on the field in the “Selected Fields” box and then the left-pointing single or (to remove all) double-arrow buttons. 5. To rearrange the fields, you may have to remove them from the right, and replace them from the left in different sequences. * Follow each step in the wizard process to complete your report. At the end of the process, you’ll be prompted to give the report a name. Do that, and click “Finish”. The report will be previewed for you. After previewing it, you may exit the report. If you were to print it, you would click on the Print icon.
15. 15. PART VI - CREATING QUERIES (simple) 1. Click the “Queries” tab. Click New. 2. Click on Design View and click "OK" 3. From the "Show Table" dialog box, click on the Salesperson Table and click "Add". The table will be added to the view table area above the grid in your query design view. Now click on "Close". 4. In the Query grid, first column, click on the drop-down arrow on the Field row. Choose the Salesperson ID field. Now do the same for each column's field, selecting a Salesperson Table field to display. Don't select all the fields - the idea here is to select only the fields you want. 5. When you've selected your fields, save the query by clicking on the diskette icon and giving your query the name Salesperson Query. Now run the query by clicking on the red exclamation point icon in the toolbar at the top of the screen. Your data will be displayed. 6. Once you've done that, click on the Design View icon in the top left of the toolbar. Experiment by changing your query, and running it each time, in the following ways: • Click on the Sort row in a column other than the Salesperson ID, and select Ascending. Run the query and view the results. Now change back to Design View and select Descending for the same field and run it. View the results. Try this with several fields. • Click on the Show button (in Design View) for a field (should be checked - so "uncheck" it) and run the query. That field should not be present. Check the field back again. • If you haven't chosen the State field to be in your query, click on the next empty field's drop-down arrow and choose it. Now you're going to select, or filter out, records. Click in the Criteria row for the State field and key in =GA. (obviously, you will have to have some employees in GA, and you should have some in other states too) Tab out of the field. Now run the query. • Try the same selection with Sex being M and then F. You should have some records of each sex so that this filter works, displaying only the male records (and then, the female records) • You can do the same thing with the Company Car Yes / No field, using it to filter only those Salespersons who drive a company car. PART VII – JOINED TABLE QUERY When you create this kind of query, using the same steps (1 through 3 above) you did before, this time add both tables from the Show Table box. The relationship you have previously created will also be in the query. Now you can follow the same steps above, selecting fields from both tables, without even displaying (or using) the Salesperson ID in the query as a field. The connection between the common Salesperson IDs will allow data such as the employee's name and his customer’s city to be displayed.
16. 16. Tables  Tables – core database objects; purpose is to store information Field – represented with columns; a specific type of information (e.g. about an employee: last name, first name) Record – represented with rows; all the information (e.g. about a specific employee: last name is Ignacio, first name is Lareina)  Datasheet View – is a display of data from a table, form, or query in a row-and-column format; this view allows the user to modify table’s data Field name – is a unique name given to each field in a table, usually an instantly recognizable name that easily correlates to data it represents Primary Key – is a unique value that identifies each record in a table and ensures only one record will be created for that particular piece of data  Design View – is the display of the design of a table, query, form, or report; this view allows the user to modify table’s structure Data type – describes the type of data a field or variable can hold, for example the field Cost can hold a data type of Currency.  AutoNumber – an auto-number is a unique number that is automatically created for each item added to a table  Currency - a currency field is comprised of dollar amounts with features such as dollar signs, commas, decimal points  Date/Time – data type contains the date and time values for the years 100 through 9999. This data type can be formatted in various ways, including general, long, short, and medium date/time  Hyperlink – data type is text saved as a link to another document using the other document’s “address” or URL  Lookup wizard – the lookup wizard allows the usage of a value from another table or list by using a list-box or combo box. The data type of the field chosen from the outside table  Memo – a memo data type allows a large amount of text and numbers, such as notes or descriptions, to be use in a field
17. 17.  Number – a number field can only be comprised of numbers, either positive or negative. Usually, this data type is chosen for data that will be used in a mathematical operation  OLE object – an OLE object is an object from another program ( such as an excel spreadsheet, a Word document, graphics, or sounds ) that are linked or embedded in an Access table  Text – a text data type is a character field that contain at most 225 characters  Yes/No – data type used for fields that have an either/or value, such as yes or no and true or false Description – is simply a detailing of the field, which allows for easier understanding of the data General Tab:  Field size- the size/type of numbers/characters allowed to be entered into the field. (EX: 255 characters, 100 numbers, etc.) * For number fields  Byte – stores whole numbers from 0 to 255  Integer – stores whole numbers from -32,768 to 32,767  Long Integer – (The default.) Stores whole numbers from -2,147,483,648 to 2,147,483,647  Single – stores negative numbers from -3.402823E38 to -1.401298E-45 and positive numbers from 1.401298E-45 to 3.40282E38
18. 18.  Double – stores negative numbers from -1.79769313486231E308 to -------- -4.94065645841247E-324 and positive numbers from 1.79769313486231E308 to 4.94065645841247E-324  Decimal – stores numbers from -10^28 -1 through 10^28 -1  Format- the layout displayed for the field. (EX: general date, short time, etc)  Input Mask- a selection of patterns for data entered into the field. (EX: SSN, zip code, etc)  Caption- the label used on a form to identify the field  Default Value- a value that is automatically entered as a default  Validation Rule- expression that can precisely define the information that will be accepted in one or several fields in a record  Validation Text- the text message that appears if the validation rule fails  Indexed- determines if duplicates are allowed in a field or not  Required- is this a required field? Lookup Tab:  Display Control- a drop-down menu from which to decide the control type for a form. (EX: textbox, drop-down list, list box)  Look-up Field – is a field that displays either a field that looks up data from existing tables or queries or a list that stores a fixed set of values
19. 19.  Relationships – association between common fields in two tables to link information in one table to information in another table One-to-one relationship – in which each record in one table can have one and only one related record in the other table One-to-many relationship – an excellent way to display this is through the use of a form containing a subform; the main, or primary, form displays one record from the “one” side of the one-to-many relationship, and the subform lists all the pertinent records from the “many” side of the relationship Many-to-many relationship – which are really two one-to-many relationships tied together through a third table  Relationship window –displays the tables and relationships in a database; it is possible to view, create, and modify relationships between tables and queries within this window. Creating Relationships 1. To create a relationship, click TOOLS then RELATIONSHIPS from the toolbar, to activate the relationships window. 2. To view the tables to which you wish to add relationships, click RELATIONSHIPS then SHOW TABLES from the toolbar. 3. At the pop-up window, select the tables you desire to add relationships to and then click the ADD button. 4. Highlight the field you wish to relate to another table by clicking it once. 5. Next, drag and drop it to the corresponding field name in the appropriate table. 6. A pop-up window will appear titled “Edit Relationship.” This window will clarify what type of relationship you are creating in the lower right corner of the window. 7. Select ENFORCE REFERENTIAL INTEGRITY if you want to ensure that the relationships you create between tables is valid. The options CASCADE UPDATE and CASCADE DELETE are then available. These options ensure that if a change is made to data in a table that is linked, the changes are reflected in the corresponding linked table. 8. Click CREATE to create the relationship.
20. 20. Forms  Form – allow you to easier enter, retrieve, display, edit and print records of the underlying table Controls – contained in a form; either display information or accept information that people enter  Form View – in which you enter data  Layout View – in which you layout the style of your form
21. 21.  Design view – in which you work with the elements of the form to refine the way it looks and works Label controls – containing text that appears in the form in Form view Textbox controls – contain data from the underlying table  Form Properties Bound – when a data in a form is linked to the table it’s based on Record source – the table Control source – the field
22. 22. Reports  Report – Summary of data for a professional look and enable sharing and printing  Report view – where you can scroll through the information in the report without the page breaks inserted when it is printed  Print Preview – in which you see your repot exactly as it will look when printed
23. 23.  Layout view – which displays the data in report but enables you to edit the layout  Design view – in which you can manipulate the design of a report without the page breaks inserted when it is printed
24. 24. Queries  Queries – are the means of manipulating the data to display in a form or a report. Queries can sort, calculate, group, filter, join tables, update data, delete data, etc. Their power is immense. The Microsoft Access database query language is SQL (Structured Query Language). The need to know SQL is not required in the early stages of learning Access. Microsoft Access writes the SQL for you, after you tell it what you want, in the Design view of the queries window. Select query – retrieves data from one or more tables and displays the results in a datasheet; can also be used to group records and calculate sums, counts, averages, and other types of totals  Duplicate query –locates records that have the same information in one or more fields that you specify  Unmatched query – locates records in one table that don’t have related records in another table Parameter query – prompts you for information to be used in the query – for example, a range of dates Crosstab query – calculates and restructures data for easier analysis Action query – updates multiple records in one operation; performs an action on the results of the selection process  Delete queries – delete records from one or more tables  Update queries – make changes to records in one or more tables  Append queries – add records from one or more tables to the end of one or more other tables  Make-table queries – create a new table from all or part of the data in one or more tables Creating Queries 1. Click the Create tab. 2. In the Other group, click Query Design. The Show Table window appears (see Figure 1, below). 3. On the Tables tab, click tblDemo. 4. Click the Add button. 5. Click the Close button. Enter Query’s First Criterion 1. Click in the first Field: cell. 2. Click the down arrow button to display the list of field names (see Figure 2). 3. Click the Donation field name. 4. Click in the Criteria: row, first cell.
25. 25. 5. Type <1 (indicating less than 1). 6. See Figure 3 for query criteria. Enter Query’s Second Criterion 1. Click in the second Field: cell. 2. Click the down arrow button. 3. Click the Last Name field (see Figure 5, below). Enter Query’s Third Criterion 1. Click in the third Field: cell. 2. Click the down arrow button to display the field names menu. 3. Click First Name (see Figure 5).
26. 26. Run and Save the Query 1. From the Design tab, in the Results group, click Run (see Figure 7). 2. Click the Save button on the toolbar. 3. In the Save As dialog box, enter qryDemo for the name of the query. 4. Click OK. 5. The query results display (see Figure 8). 6. Close or minimize the query.
27. 27. Macros and Modules  Macro – simple program that performs multiple actions; used to make routine database actions available as command buttons in forms, which help less experienced users work in your database  Modules – are Microsoft Visual Basic for Applications (VBA) programs; used to carry out tasks that are too complex to be handled with macros