MS Access 2003 Access is a database program that allows you to store, retrieve, analyze, and print information. Individuals use databases for various purposes. Businesses use databases to manage customer files, track orders and inventories, and for marketing purposes. Individuals keep track of household expenses or personal addresses, and teachers manage student grades and other student information. When first starting to use Access you might think to yourself why not use Excel because it seems much less confusing. Access gives you the ability to manage thousands, of pieces of data in an organized, efficient, and accurate manner. By running queries you can retrieve the exact data you need and create a report in the exact fashion you need. Let s begin by looking at the toolbar and menu of Access. OfficeLinks Relationships New Object Analyze Properties OfficeLinks : o Options to Merge It with MS Word (Mail Merge) o Publish It with MS Word (Report in Word), o Analyze It with MS Excel (Exports to an Excel spreadsheet). Relationships : Displays the relationships window so you can view, edit, or define relationships between tables and queries. New Object : Automatically creates a new object such as a table, query, form, report, page, macro, or module. Analyze : The Analyze Table can help you create a relational database from a set of data. Analyze Performance analyzes the performance of a query. Documenter helps you document a query or report. Properties : Displays the property sheet for the selected item, such as a table field or form control. 1
I. Opening a New Database When opening Access you have the choice to open an existing database or create a new file. 1. Select Create a new file. 2. Click Blank database 3. Click the Save in: drop down arrow and select location to save the database. 4 Type a name for your database in the File name box and click create. Database Window 4. The Database window will now be displayed. 5. Double click Create table in Design view to open the design view of the database table. 2
II. Tables Tables store data and organize the information into a usable structure. Follow the steps below to enter field names for your data. A. Creating a Table Design View of a Database Table Close Table 1. Type Employee Number in the Field Name column. 2. Tab to the Data Type column. The data type defaults to text and the Field Properties box opens. 3. Tab to the Description field and type EmployeeNumber without a space. 4. Click the Primary Key button on the tool bar. 5. Press the F6 key and set the Field Size at 20. This sets the character size for the field. 6. Do not change the Required, Allow Zero Length or Unicode Compression properties. 7. The primary key should be indexed and prohibit duplicates. 8. The Indexed property defaults to Yes (No Duplicates) when you click the Primary Key. 9. Repeat steps 1-3 and then 5 and 6. Change the Indexed property to Yes (Duplicates OK).by double clicking the property to enter the field names for FirstName and LastName. Notice that only the EmployeeNumber will be set as the Primary Key. 10. Close the Table by clicking the black X, located at the upper, right corner of the table window. 11. Click Yes to save the changes. 12. When prompted, name the table Employee and click OK. 3
Database Window B. Editing a Table 1. With the Employee Table highlighted, click the Design View to open the table in design view. 2. Add a field named Department. Click the empty field under Last Name and type Department in the Field Name. The Data Type is Text and the Description is Employee department. Set the Field Size equal to 20 and Indexed to Yes (Duplicates OK). 3. Add another field name for the employee s date of hire. The Field Name should be DateHired. Choose Date/Time as the Data Type and type Employee s hire date as the Description. Select Short Date as the Format property. Change the Indexed property to Yes (Duplicates OK). 4. You can change the order of the fields that you have entered. Click the black arrow next to the Date Hired field. This will highlight the entire row in black. With the left-mouse button pressed, drag the Date Hired field above the Department field. 4
Release the left-mouse button. The Date Hired field will now be positioned above the Department field. 5. Close the table and select Yes when prompted to save the table. C. Adding Data to a Table 1. In the Database Window, double click the Employee Table to open it in Datasheet view. 2. The Datasheet view will contain columns for each of the database fields you previously entered. Each row below the column headings represent a record. 3. Fill in the information for each field as shown below. 4. After each field press the tab key to advance to the next field. 5. Close the Employee Table. D. Importing Data in to a Table Access allows you to import data from another program. Spreadsheets (MS Excel) are the most common source of imported data. 1. Insert the floppy disk in drive A. 2. Click File on the menu bar and then Get External Data. 3. Select Import. 4. Click the down arrow in the Look in window and select the A: drive. 5. Click the down arrow in the files of type window and choose Microsoft Excel (*.xls). 6. Click the Customer.xls file to highlight it and then select Import.. 5
7. The Import Spreadsheet Wizard will open. 8. With Show Worksheets bulleted and Sheet1 highlighted, click Next. 9. On the next screen, make sure First Row Contains Column Headings is checked and click Next. 10. The next screen will prompt you to designate a location to save your data. Select In a New Table and click Next. 11. You will now set the properties for the imported fields. Make sure Customer Number is in the Field Name window. Because Customer Number will be designated the primary key for this table, you will need to change the Indexed field toyes (No Duplicates). Click Cust First Name to highlight the field and choose Yes (Duplicates OK) from the Indexed dropdown box. Repeat this process for the remaining fields. Use the horizontal scroll bars to select the fields. Click Next when all fields have been selected and the Indexed property adjusted. 12. The next screen allows you to assign the primary key to a field. Click the Choose my own primary key radio button. With Customer Number in the dropdown window click Next. 13. Next, change the name of the table from Sheet1 to Customer and click Finish and OK when prompted. 6
14. In the Database Window, open the Customer Table in design view to edit the field properties. Change the Data Type for all fields to Text. Set the Field Size for the Customer Number, Last Name, First Name, Address, and City fields to 20. Set the Field Size for State to 2 and for Zip Code to 5. Close the Customer table and click Yes when prompted to save the changes. Choose Yes to the warning message about Some Data May Be Lost. 15.Repeat steps 2-10 to import the Vehicles Table when setting the properties Vin Number will be indexed as the Primary Key. Change Indexed to Yes (no Duplicates). Set the remaining field Indexed properties to Yes (Duplicates OK). 16. In the Database Window, open the Vehicles Table in design view to edit field Properties. Change the Data Type for all fields except Price to Text. Change the Data Type for Price to Currency Set the Field Size for the Vin Number, Make, and Model to 10, Year to 4, and Color to 20. Close the Vehicles Table and click Yes when prompted to save the changes. Choose Yes to the warning message about Some Data May Be Lost. 17. Create a Sales Table in Design View with the following fields and properties. Sales Number data type Text field size 5 this field is the Primary Key Date Of Sale data type Date/Time, format Short Date, and indexed Yes (Duplicates OK) Customer Number data type Text field size 20 indexed Yes (Duplicates OK) Employee Number data type Text field size 20 indexed Yes (Duplicates OK) Vin Number data type Text field size 10 indexed Yes (Duplicates OK) Sold Price data type Currency indexed Yes (Duplicates OK) Close the Sales Table and click Yes when prompted to save the changes. III. Relationships Relationships are used to define the way data from one table relates to data from another table. When two or more tables are created you will need to show Access how the tables relate to one another. 1. Click the Relationships that is located on the Database Toolbar. 2. Highlight all tables by holding the shift key down and clicking the tables that are not highlighted. 3. Click the Add and then Close buttons. 4. To create a relationship click and drag Employee Number from the Employee Table to the Employee Number in the Sales Table. Release the mouse button. 7
5. In the Edit Relationships window, click the Enforce Referential Integrity, Cascade Update Related Fields, and Cascade Delete Related Records then click the Create. The Relationship Type: is One-To-Many. 6. Create the other two relationships by clicking and dragging Customer Number from the Customer Table to Customer Number in the Sales Table and Vin Number from the Vehicles Table to Vin Number in the Sales Table. Remember to click the Enforce Referential Integrity, Cascade Update Related Fields, and Cascade Delete Related Records check boxes in the Edit Relationships dialog box. 7. Close the Relationships Window and click Yes to save changes. IV. Forms New Object 1. Highlight the Sales table in the Database window. 2. Click the down arrow on the New Object, located on the database toolbar. 3. Select AutoForm from the drop-down list to automatically create and open the form. 4. Create records by adding the following information to each field Sales Number Date Of Sale Customer Number Employee Number Vin Number Sold Price S1111 02/03/2003 11111 22221 00112233 $1000.00 S1222 03/04/2002 11112 22222 00122233 $9000.00 S1311 01/18/1995 11113 22221 00132233 $16000.00 5. Close the form and click Yes when prompted to save. Title the form Sales. V. Queries Queries are questions that are posed to the database. They allow the user to extract specific records from the database. Query 1. In the Database window, click the Query. 2. Double click the option to Create query by using wizard. 8
3. Click the Tables/Queries drop-down arrow and select the Sales Table. 4. Using the add all field button. Add all fields from the Available Fields column to the Selected Fields column. Click the Tables/Queries drop down arrow and select the Customer Table. Using the add one field button add the fields Customer First Name and Customer Last Name. Do this same procedure to add First name and Last Name from the Employee Table. Add All Add One 5. Click Next. 6. With Detail (shows every filed of every record) bulleted click Next. 9
7. You will be prompted to name your query. Enter Sales Query in the text box. 8. Leave the radio button checked to Open query to view information. 9. Click Finish. 10. The query will open in Datasheet View. Click the Design View button. 11. Arrange the fields by positioning the curser just above the field name to get a solid black arrow. Click to highlight the field column then click and drag the field to the desired position. 12. Add the number 22221 to the Criteria box of the Employee Number field and press the tab key. 13. Click the Run button to access the information that you queried. 14. Click the View button, highlight the Criteria field number 22221, and press Delete. 15. Close the query window and select Yes when prompted to save the changes. VI. Reports Reports are often used to print query results or data tables. 1. Click the Reports in the Database Window. Report 10
2. Double click Create report by using wizard. 3. Click the Tables/Queries dropdown arrow and select the Sales Query. 4. Add Date Of Sale, Customer First Name, Customer Last Name, Employee Number, Employee First Name, Employee Last Name, Vin Number using the Add button. 5. Click the Tables/Queries dropdown arrow and select the Vehicles Table. 6. Add Make, Model and Sold Price using the Add button. 7. Click the Tables/Queries dropdown arrow and select the Sales Query. 8. Add Sold Price using the Add button. 9. Click Next 10. Choose by Sales Query from the How do you want to view your data box. Click Next twice. 11. Choose Employee Number from the first Sort dropdown box. 12. Proceed through the wizard by selecting the Next button. 11
12. When prompted to name the Report, type Sales By Employee. 13. Click Finish. 14. You will now be able to view your Report. 15. You can click the Design View to change the design of your report. VII Macros Macros consist of a series of actions that Access will perform when the macro is run. 1. Click the Macro in the Database Window. 2. Click the New in the Database Window. Macros 3. Click the Dropdown Arrow in the Macro Window and choose OpenReport. 4. Tab to Comment and type Preview Sales By Employee Report. 5. Press the F6 Key (this takes you to the Action Arguments for the macro) click the Dropdown Arrow and choose Sales By Employee for the Report Name. 6. Tab to View and click the Dropdown Arrow and choose Print Preview. 7. Click the empty Action Box under OpenReport and choose Maximize from the Dropdown Box. 8. Close and save the macro. Name it Preview Sales By Employee Report when prompted. 12
9. Highlight, Preview Sales By Employee Report Macro, click the Run. This shows the preview of the report. VIII Command s A command button executes a command when clicked. 1. Click the Form in the Database Window, highlight the Sales Form and click the Design. Toolbox 2. Maximize the window if needed and enlarge the form by putting your mouse on the bottom right corner and clicking and dragging down. The Toolbox should be indented. 3. Make sure the Control Wizards is recessed. Click the Command and move the mouse pointer, whose shape has changed to a plus sign with a picture of a button two lines under the label Sold Price and click and drag to draw a command button. Control Wizards Command 13
4. Click Record Operations and make sure Add New Record is highlighted. Click Next. 5. Click the Text Radio. Add Record is the desired text. Click Next. 6. Type Add Record for the button name. Click Finish. Form View 7. Click the Form View 14
8. Click the Add Record 9. Add the following record to the form. Sale Number S1411 Date Of Sale 01/11/2002 Customer Number 11115 Employee Number 22222 Vin Number 00142233 Sold Price $16,500.00 10. Click the Close to close the form. 11. Click Yes to save changes. 15