chapter a solutions creating and using databases with ......step if the animals table in the...

12
CHAPTER A SOLUTIONS Creating and Using Databases with Microsoft Access The solutions in this appendix are for you to use if you get stuck when doing an On Your Own activity in the chapter. To learn how to teach yourself a computer skill, always try the On Your Own activity first before turning to these solutions. On Your Own Solution A-1 How to Explore the AnimalShelter Database and the Access Window Because you cannot edit a file on a DVD, you need to first copy it to another location. Follow these steps to copy the AnimalShelter database on the DVD to a USB flash drive, hard drive, or other local storage device and open the file: Step 1. Insert the DVD in the optical drive. Using Windows Explorer, locate the AnimalShelter database file in the Extra Chapters folder on the DVD. If Windows is set to show file extensions, the filename and extension appear as AnimalShelter.accdb. Copy the file. Step 2. Go to the storage device where you want to put the file and paste the file to this new location. Step 3. Click Start, All Programs, Microsoft Office, Microsoft Access 2010. The Microsoft Access window opens with the File tab selected and the Backstage view showing. Step 4. Click Open. The Open dialog box appears. Locate the AnimalShelter database file on your local storage device. Click Open. The name of the open database appears in the title bar of the Access window. Note that you can also open an Access database by double-clicking the database file in Windows Explorer. Step 5. The yellow Security Warning bar appears below the Access Home ribbon. Click Enable Content to close this security bar. Follow these steps to explore and edit the database: Step 1. To open the Animals table, double-click Animals in the left pane. Records in the table appear in the right pane in the Datasheet view. Datasheet View appears on the left side of the status bar at the bottom of the Access window. Step 2. Identify on your own computer the items labeled in Figure SA-1. Step 3. To add a new record to the table, click the Animal Type field in the last record of the table, which has an asterisk (*) on the left. Enter Dog or Cat in the Animal Type field. Press Tab to move to the next field on the right. A new counting number is automatically inserted in the Animal ID field. You cannot enter a value into this field. Step 4. Enter values for the Animal Name, Gender, Breed, Weight, and Date Received fields. Here is what happens if you enter invalid data: . If you try to enter a letter other than M or F into the Gender field, an error message appears in a dialog box. Click OK and type M or F into the Gender field. . If you try to enter a value other than a date into the Date Received or Date Placed field, an error message appears. To correct the problem, click Enter new value and enter a valid date. Step 5. To close the Animals table, right-click the Animals tab and click Close.

Upload: others

Post on 23-Jan-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

Chapter a SolutionSCreating and Using Databases with Microsoft AccessThe solutions in this appendix are for you to use if you get stuck when doing an On Your Own activity in the chapter. To learn how to teach yourself a computer skill, always try the On Your Own activity first before turning to these solutions.

On Your Own Solution A-1 how to explore the animalShelter Database and the access Window

Because you cannot edit a file on a DVD, you need to first copy it to another location. Follow these steps to copy the AnimalShelter database on the DVD to a USB flash drive, hard drive, or other local storage device and open the file:

Step1. Insert the DVD in the optical drive. Using Windows Explorer, locate the AnimalShelter database file in the Extra Chapters folder on the DVD. If Windows is set to show file extensions, the filename and extension appear as AnimalShelter.accdb. Copy the file.

Step2. Go to the storage device where you want to put the file and paste the file to this new location.

Step3. Click Start, AllPrograms, MicrosoftOffice, MicrosoftAccess2010. The Microsoft Access window opens with the File tab selected and the Backstage view showing.

Step4. Click Open. The Open dialog box appears. Locate the AnimalShelter database file on your local storage device. Click Open. The name of the open database appears in the title bar of the Access window. Note that you can also open an Access database by double-clicking the database file in Windows Explorer.

Step5. The yellow Security Warning bar appears below the Access Home ribbon. Click EnableContent to close this security bar.

Follow these steps to explore and edit the database:

Step1. To open the Animals table, double-click Animals in the left pane. Records in the table appear in the right pane in the Datasheet view. Datasheet View appears on the left side of the status bar at the bottom of the Access window.

Step2. Identify on your own computer the items labeled in Figure SA-1.

Step3. To add a new record to the table, click the Animal Type field in the last record of the table, which has an asterisk (*) on the left. Enter Dog or Cat in the Animal Type field. Press Tab to move to the next field on the right. A new counting number is automatically inserted in the Animal ID field. You cannot enter a value into this field.

Step4. Enter values for the Animal Name, Gender, Breed, Weight, and Date Received fields. Here is what happens if you enter invalid data:

. If you try to enter a letter other than M or F into the Gender field, an error message appears in a dialog box. Click OK and type M or F into the Gender field.

. If you try to enter a value other than a date into the Date Received or Date Placed field, an error message appears. To correct the problem, click Enternewvalueand enter a valid date.

Step5. To close the Animals table, right-click the Animals tab and click Close.

Page 2: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

A-48 Solutions Appendix

FigurESA-1

A table in a database is made up of records (rows) and fields (columns).

On Your Own Solution A-2 how to use the Design View of the animals table

Follow these steps to view the Animals table in Design view:

Step1. Using the AnimalShelter database, double-click the Animals table in the left pane. The Animals table opens. Right-click the Animals tab in the right pane and select DesignView from the shortcut menu. The Design view appears. Design View is listed in the status bar at the bottom of the Access window.

Step2. In the Field Name column, click the gender field. The Field Properties pane for this field displays at the bottom of the Access window.

Step3. Select the text AcceptedtextisMorF. Replace this text with OnlyMorFisallowed, as shown in Figure SA-2.

Page 3: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

Chapter a SolutionS: Creating and Using Databases with Microsoft Access A-49

FigurESA-2The Validation Text in the Field Properties pane has been changed.

Step4. To save your design changes, right-click the Animals tab and select Save from the shortcut menu.

Step5. To return to Datasheet view, right-click the Animals tab and select Datasheetview.

Step6. Enter a new record or edit an existing record. If you enter text other than M or F in the Gender field, a dialog box appears showing Only M or F is allowed. Click OK and correct the problem.

Follow these steps to sort and filter the records in the Animals table:

Step1. Look in the status bar for Datasheet View to verfiy the Animals table is showing in the Datasheet view. Click the drop-down arrow to the right of the Gender field name. Click SortAtoZ. The data is sorted by Gender.

Step2. Click the drop-down arrow to the right of the Animal ID field. Click SortSmallesttoLargest.

Step3. Click the drop-down arrow to the right of the Animal Type field. Uncheck (SelectAll) and check Cat. Click OK. Only cats are listed.

Step4. To remove the filter, click the drop-down arrow to the right of Animal Type. Check (SelectAll)and click OK. All records are listed.

Step5. To delete a record, use one of these methods:

. Right-click the box to the left of the record and click Deleterecord in the shortcut menu. A dialog box appears. Click Yes to delete the record.

. To select the record, click the box to the left of the record. The entire record is selected. On the Home rib-bon, click Delete. A dialog box appears. Click Yes to delete the record.

Step6. Right-click the Animals tab and click Save on the shortcut menu.

Page 4: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

A-50 Solutions Appendix

On Your Own Solution A-3 how to Create and run a Query

Follow these steps to create and run a query that displays only animals that have been placed with new owners:

Step1. If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be listed in the right pane and Datasheet View appears in the status bar.

Step2. On the Create ribbon, click QueryDesign. The Show Table dialog box appears (see Figure SA-3). Verify the Animals table is selected. Click Add. The Animals table is added to the query. Click Close to close the dialog box.

FigurESA-3Use the Show Table box to select tables to use in the query.

Step3. Double-click the AnimaliD field in the list of fields for the Animals table. The Animal ID field is added to the field list at the bottom of the query design pane. Double-click AnimalName, DatePlaced, and NewOwner to add these fields to the query. Four fields are now listed in the query design.

Step4. In the lower pane of the query design, click in the box in the Animal Name column in the Sort row. A drop-down arrow appears in the box. Click the drop-down arrow. In the drop-down list that appears, click Ascending.

Step5. Click in the box in the Date Placed column in the Criteria row. Type >0 in the box.

Step6. To save the query, right-click the Query1 tab and click Save. The Save As dialog box appears. Type Placements and click OK. The Placements query is listed in the Navigation pane of the Access window. The query tab is named Placements and is currently selected.

Step7. To run the query, right-click the Placements tab in the right pane and click DatasheetView. Only records that have values in the Date Placed field are listed. Only the four fields selected for the query are listed. Records are listed sorted by Animal Name.

Follow these steps to practice opening and closing a query, table, database, and the Access application:

Step1. To close the Placements query, right-click the Placements tab and select Close from the shortcut menu. The Placements tab disappears.

Step2. To close the Animals table, right-click the Animals tab and select Close. If you have made changes to the table design since you last saved it, a dialog box appears asking whether you want to save your changes. If so, click Yes. The Animals tab disappears from the right pane.

Step3. To open the Animals table, double-click it in the left pane.

Step4. To open the Placements query, double-click it in the left pane.

Step5. To close the database, click the File tab. Click CloseDatabase. Your changes are saved and the database is closed.

Step6. Close the Access window.

Step7. Using Windows Explorer, locate and double-click the AnimalShelter database file on your local storage device. The database opens in an Access window.

Page 5: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

Chapter a SolutionS: Creating and Using Databases with Microsoft Access A-51

Step8. To close the AnimalShelter database, click the File tab and click CloseDatabase in the Backstage view. The Access window still remains open, but no database is in view.

On Your Own Solution A-4 how to Create a Database

Follow these steps to create the DogShow database:

Step1. Open Access. Click the File tab and click New. Click Blankdatabase. Click the Browse button to the right of the File Name box. The File New Database dialog box appears.

Step2. Navigate to your USB flash drive, hard drive, or another location given by your instructor and select the folder where you want the database to be stored. Enter DogShow in the File name box. For example, Figure SA-4 shows the location as the Computer Class folder on a USB flash drive. Click OK to close the dialog box.

FigurESA-4Point to the location to store the database and name the database file.

Step3. Verify the filename and location are correct and click Create. The database file is created and Access assigns the file extension of .accdb to the file. The new database looks like that in Figure SA-5.

not Working? If the Access window does not open when you double-click the AnimalShelter database, your Windows settings might be wrong. Ask an experienced technician to help you configure Windows to associate a .accdb file with Microsoft Access for your computer.

Page 6: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

A-52 Solutions Appendix

FigurESA-5A new database has one table, which has one field.

Follow these steps to change the names of the table and the field and add seven more fields to the Dogs table:

Step1. Right-click the Table1 tab and click DesignView in the shortcut menu. The Save As dialog box appears. Change the name of the table to Dogs and click OK.

Step2. Change the name of the ID field to DogiD. Change the Data Type of the field from AutoNumber to Text.

Step3. Tab to the next Field Name and enter DogName. Set the Data Type to Text.

Step4. Tab to the next Field Name and enter FirstName. Set the Data Type to Text.

Step5. Tab to the next Field Name and enter LastName. Set the Data Type to Text.

Step6. Tab to the next Field Name and enter Street. Set the Data Type to Text.

Step7. Tab to the next Field Name and enter City. Set the Data Type to Text.

Step8. Tab to the next Field Name and enter State. Set the Data Type to Text.

Step9. Tab to the next Field Name and enter Zip. Set the Data Type to Text.

Step10. Click in the State field name to select that field. In the Field Properties pane at the bottom of the window, change the Field Size from 255 to 2.

Step11. Select the Zip field and change the Field Size from 255 to 5.

Step12. To Verify the Dog ID is the primary key, look for the key icon to the left of the Dog ID field name.

Step13. To save your changes to the table, right-click the Dogs tab and click Save.

Follow these steps to create the Entries table:

Step1. Click the Create tab. On the Create ribbon, click Table. A new table is created.

Step2. Right-click the Table tab and click DesignView. In the Save As dia-log box, change the table name to Entries and click OK.

Step3. Change the ID field name to Class and change the data type from AutoNumber to Text.

Step4. Add a new field named DogiD. In the Data Type column, select Text.

Step5. Add a new field named EntryFee. In the Data Type column, select Currency.

Page 7: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

Chapter a SolutionS: Creating and Using Databases with Microsoft Access A-53

To set the primary key for the Entries table, follow these steps:

Step1. Click the selection box to the left of the Class field. This row is selected. Hold down your Shift key and click the selection box to the left of the Dog ID field. Both rows are now selected.

Step2. On the Design ribbon, click PrimaryKey. A key icon appears beside both fields indicating the two fields are now the primary key for the table (see Figure SA-6).

FigurESA-6Select two fields and make the two fields the primary key.

Step3. To save the Entries table, right-click the Entries tab and select Save.

Step4. Right-click the Entries tab and click Close on the shortcut menu.

Follow these steps to enter sample data into the Dogs table:

Step1. If necessary, open the Dogs table. Right-click the Dogs tab and click DatasheetView.

Step2. Enter the following sample data into the Dogs table or make up your own data:

DogiD DogName FirstName LastName Street City State Zip

D05 Daisy Sandy Adams 100 Apple Lane Smithville OH 33000

D007 Sir Edward Louie Jackson 400 Maryville Hwy Knoxburg OH 50000

D10 Prissy Betty Clear 300 Mary Street Smalltown OH 33333

D4 Tildie Bethany Miller 1216 Bobwhite Dr Stanton OH 55555

D90 Bonita Latoya Jones 378 Maple Street Lakeville OH 44444

D70 Prissy Lorraine Quency 344 Lee Street Woodson OH 22222

Step3. Try to enter two records in the Dogs table that have the same Dog ID. Note that an error occurs and you must correct the problem. Because the Dog ID is the primary key for the Dogs table, duplicate entries are not allowed.

Step4. To save the Dogs table, right-click the Dogs tab and click Save. To close the Dogs table, right-click the Dogs tab and click Close.

Follow these steps to enter sample data in the Entries table:

Step1. Double-click the Entries table in the left pane. The Entries table opens in Datasheet view.

Step2. Enter the following sample data into the Entries table or make up your own data:

Page 8: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

A-54 Solutions Appendix

Class DogiD EntryFee

Agility D007 15

Agility D90 15

Showmanship D007 12

Showmanship D05 12

Showmanship D4 12

Showmanship D70 12

Showmanship D90 12

Working D007 15

Working D05 15

Working D10 15

Step3. Try to enter two records in the table that have the same Class and Dog ID. Note that an error occurs and you must correct the problem. Because the Class and Dog ID make up the primary key for the Entries table, duplicate entries for Class and Dog ID are not allowed.

Step4. Right-click the Entries tab and click Save on the shortcut menu. Right-click the Entries tab again and click Close on the shortcut menu.

On Your Own Solution A-5 how to relate two Database tables

The details of relating two database tables and verifying the relationship works are given in the chapter and are not repeated here.

On Your Own Solution A-6 how to use a lookup Field to protect Data integrity

The details of creating and using a lookup field to protect data integrity are given in the chapter and are not repeated here.

On Your Own Solution A-7 how to Create and use Detailed and Split Forms

Follow these steps to create and use the OneDog form:

Step1. Using the DogShow database, click the Dogs table in the left pane so it is selected. It is not necessary to open the table.

Step2. Click Form on the Create ribbon. The Dogs form is created.

Step3. Right-click the Dogs form tab and click Save in the drop-down menu. In the Save As dialog box, name the form OneDog and click OK. The form is saved, and you can see it listed in the left pane under Forms.

Step4. On the Design ribbon, click the drop-down arrow under View and click FormView.

Step5. Click the left and right arrows at the very bottom of the form to step through records in the Dogs table. Click the Firstrecord arrow to go to the first record. Click the Lastrecord arrow to go to the last record.

Step6. To enter a new record in the Dogs table, click the New(blank)record arrow at the very bottom of the form. Enter data for a new record.

not Working? The OneDog form provides two sets of arrow buttons used to step through records. One set applies to the Entries table and the other set applies to the Dogs table. Use the set at the very bottom of the form that applies to the Dogs table.

Page 9: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

Chapter a SolutionS: Creating and Using Databases with Microsoft Access A-55

Step7. To search for text, first click in the search box at the bottom of the form. Enter Betty in the box. The third record appears with Betty highlighted.

Step8. To save the form, right-click the OneDogtab and click Save in the shortcut menu. Right-click the OneDog tab again and click Close.

Step9. Double-click the Dogs table in the left pane. The Dogs table opens in Datasheet view. If you don’t see your new record, press F5 to refresh the data. Close the Dogs table.

Do the following to create a split form to edit the Entries table:

Step1. In the left pane, click the Entries table to select it. It is not necessary to open the table.

Step2. On the Create ribbon, click MoreForms and click SplitForm. The split form is created.

Step3. Right-click the Entries form tab and click Save. In the Save As dialog box, name the form SplitEntries and click OK.

Step4. To switch to Form view, click the Form View button in the status bar at the bottom of the Access window.

Step5. Using the arrows at the bottom of the form, step through the records and go to the first and last records.

Step6. Add a new record to the Entries table.

Step7. Use the Search box at the bottom of the form to search for text. Enter Working. The first record that contains Working appears. Press Enter to step through other records that contain this text.

Step8. To save the form, right-click the SplitEntriestab and click Save in the shortcut menu. Right-click the SplitEntries tab again and click Close.

Step9. Double-click the Entries table in the left pane. The Entries table opens. If necessary, press F5 to refresh the data. Close the table.

On Your Own Solution A-8 how to Create a Query that includes a Calculation

Follow these steps to create the Fees query:

Step1. Using the DogShow database, click QueryDesign on the Create ribbon. The Show Table box appears. (If it does not appear, click ShowTable on the Design ribbon.)

Step2. In the Show Table box, click Entries and click Add. Click Close to close the Show Table box.

Step3. In the Entries box, double-click Class. Class is added as the first column in the query. Double-click DogiD to add it as the second column. Double-click EntryFee to add it as the third column in the query.

Step4. To save the query, right-click the Query1 tab and click Save in the drop-down menu. In the Save As box, name the query Fees and click OK.

Step5. To view the data in the query, right-click the Fees tab and click DatasheetView.

Step6. Right-click the Fees tab and click DesignView. To sort rows in the query, click the box in the Class column and Sort row. A drop-down arrow appears. Click the drop-down arrow and click Ascending.

Step7. Return to Datasheet view to see the data, which is sorted by Class.

Step8. On the Home ribbon, click Totals in the Records group. A total row is added to the query.

Step9. Click in the Entry Fee column of the total row. Then click the down arrow that appears. In the drop-down list, click Sum. A sum is added to the total row.

Step10. Compare your query to that shown in Figure A-20 in Chapter A. Your data might be different. Verify the Entry Fee column is summed in the Total row. Correct any problems you see. Save and close the query.

On Your Own Solution A-9 how to Create a Query that uses two tables

Follow these steps to create the ClassRoster query:

Step1. Using the DogShow database, click QueryDesign on the Create ribbon. The Show Table box appears. Add the Entries table to the query. Add the Dogs table to the query. Close the Show Table box.

Step2. To break the relationship between the two tables, click on the line connecting the tables and press the Delete key. The line disappears.

Page 10: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

A-56 Solutions Appendix

FigurESA-7The Join Properties box shows how records will be selected for a query.

not Working? If you don’t see Join Properties in the shortcut menu when you right-click the line, try moving your pointer more toward the center of the line and then right-click again.

Step5. Verify the Entries table is on the left and the Dogs table is on the right. Select 2:includeALLrecordsfrom‘Entries’andonlythoserecordsfrom‘Dogs’wherethejoinedfieldsareequal. Click OK to close the box.

Step6. Double-click the following fields to add them to the query:

a. Class in the Entries table

b. DogiD in the Entries table

c. DogName in the Dogs table

d. FirstName in the Dogs table

e. LastName in the Dogs table

Step7. At the bottom of the query design pane, click the box in the Class column and the Sort row. Select Ascending from the drop-down list. Records in the query will be sorted by Class in ascending order.

Step8. Right-click the Query1 tab and click Save. Name the query Classroster.

Step9. Return to Datasheet view and view the results of the query. The query should list all the records in the Entries table and related data in the Dogs table.

Step10. Check your work against Figure A-21 in Chapter A. Your data might be different from that shown, but the column headings should be the same. The number of records in the query appears at the bottom of the query. Compare this number to the number of records listed at the bottom of the Entries table. The numbers should be the same.

Step11. If you have made any changes since you last saved the query, save the query again.

Step12. To close all open objects in the database, look for tabs in the right pane. If you see any, right-click it and select Close. Save any changes as you close an object.

Step3. Press and drag the Dog ID field from the Entries table to the Dog ID field on the Dogs table. A line is drawn. Be sure to drag from the Entries table to the Dogs table and not in the other direction.

Step4. Right-click the line joining the two tables and select JoinProperties from the shortcut menu. The Join Properties box appears (see Figure SA-7).

Page 11: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

Chapter a SolutionS: Creating and Using Databases with Microsoft Access A-57

On Your Own Solution A-10 how to Create Mailing labels from a Single table

The details of creating mailing labels from a single table are given in the chapter and are not repeated here.

On Your Own Solution A-11 how to Create a report from a Query

Follow these steps to create the class roster report:

Step1. Using the DogShow database, double-click the Classroster query in the left pane. The query results appear in the right pane.

Step2. On the Create ribbon, click report. A report is created using the selected query. Right-click the report tab and click Save. Name the report Classrosterreport.

Step3. To change the title of the report, click in the title box and change the text to ClassrosterSenttoringMaster.

Step4. To narrow the Class field, press and drag the right side of the field selection box to the left, as shown in Figure SA-8.

FigurESA-8Press and drag a selection box to narrow the field width on the printed report.

Step5. Narrow the other fields so all columns fit on a single page without spilling off the right side of the page, as shown in Figure SA-9.

Page 12: Chapter a SolutionS Creating and Using Databases with ......Step If the Animals table in the AnimalShelter database is not open, open it. Records in the Animals table should be 1

A-58 Solutions Appendix

FigurESA-9Narrow all columns so they all fit across one page.

Step6. Hover over the page number box until your pointer changes to a four-headed arrow. Then press and drag the box to the left so it does not spill off the page.

not Working? If you make a mistake as you work, click the Undo button in the title bar and try again.

Step7. To sort the records by Class, click group&Sort on the Design ribbon. The Group, Sort, and Total pane appears at the bottom of the Design view.

Step8. Click Addasort and click Class. The records are sorted by Class.

Step9. To group the records by Class, click Addagroup and click Class. A Class Header is added to the report.

Step10. To change to Report view, click the drop-down arrow under View on the Home or Design ribbon and click reportView.

Step11. To change to Print Preview view, select PrintPreview under View on the Home or Design ribbon. The print preview appears. To close the view, click ClosePrintPreviewon the Print Preview ribbon.

Step12. To save the report, right-click the Classrosterreport tab and click Save on the shortcut menu.