Computer Training & Support Services Academic Computing 224 Weber Building (970) 491-7653 & Networking Services Access 2000 Part 1 Converting a Database Access will only allow you to modify a database that was created or converted to the current version. If you have a database created in an earlier version, you may: 1) open the database in the Access 2000 in view mode only (no modifications allowed); or 2) convert the database to Access 2000. If you choose to convert, a new database file is created, leaving the previous database file intact. Access 2000 will allow you to save an open database in the earlier version of Access (97). To use this, select Tools, Database Utilities, and click To Prior Access Database Version. General Database Concepts & Terms What is a database? A database is an organized collection of data related to a particular topic or purpose. The purpose of a database application is to provide the means to store and retrieve data in an organized and efficient manner. Access is a relational database A relational database consists of multiple tables linked together by at least one common field. Each table is a storage container and contains facts about a single topic only. For example, one table would not contain information about both students and faculty. When you use your data, you can combine fields from more than one table (if a relationship exists between the tables) through the use of queries. After the tables are created, relationships are defined to link the related data together by the field(s) they have in common. Terms A flat-file database contains all the information about your topic in one table; it does not physically interconnect with or point to other tables. A relational database consists of a collection of one or more tables that “relate” to each other through at least one field they have in common. Relationships are created to link separate tables that contain related data together. A relationship works by matching data in key fields – usually a field with the same name in both tables. A table is a data storage unit. Tables should contain data about one topic only and are comprised of database records. D:\533579935.doc Page 1 A database record contains all the information about a single item. A record is represented by a horizontal row in a table and is divided into fields. A field is the smallest division of a record and is represented by a column in the table. The Database Window (Opening a Database) An Access database is a collection of objects, not just a single table of data. One database file contains the tables as well as queries, forms, reports, and other objects that help you use the information in the database. Creating a new database or opening one that already exists is done through the File Menu. Click on File, then New Database or Open Database, depending on whether you are creating a new one or opening an existing database. Once you have given the name of the database, the Database Window will appear. The Database Window is the command center for the database. From there you create and use objects in your database. To edit or view an existing object, simply click the appropriate object button (tab) and highlight the object name. As you create objects and open new windows in Access, the menu bar and toolbar change accordingly to display commands and options that are applicable for working in each window. Access Database Objects An Access database may consist of the following objects. Note: In Access 2000 each open object will appear as a button on the Windows Taskbar. Table - Form Report Query - D:\533579935.doc Tables are the data storage units and are the only object required in a database. All data reside in a table. Each table should contain data about one subject only. For example, a single table should not contain information about students and classes. Relationships are created between tables to show how the data from one table is related to data in another table. Tables organize data into fields and records. A table may be contained in the same database file or you may attach to tables residing in other databases or applications. One must define the table structure before creating any of the other objects listed below. Forms are used to display data from tables or queries for viewing, editing, or entering data. Reports summarize and present data from tables and queries for printing. A query is a way to view selected data from one or more related tables. Through a query you may select the fields to view from multiple tables and also set criteria statements to select the specific records you wish to include. Query results may be viewed, edited, or used as the basis for a form or report. Page 2 Macros Modules - Automatically carries out a task or a series of tasks for you. For example, you could write a macro to run reports for you on a weekly basis. A set of procedures and statements stored together which are written in Visual Basic for Applications (VBA) programming language. Table Design vs. Table Datasheet View To view the data within a table, open the table in Datasheet view. Do this by clicking on the table name and then choose Open from the database window toolbar or double-click on the table name. To change a table’s structure you must be in Design view. You can toggle between the Design and Datasheet view by clicking on the first button on the toolbar. Datasheet View Data may be entered, edited, or viewed through a table’s datasheet view. If you prefer, you may optionally create a form based on your table for entering/editing data. To view the data in a table, click on the Tables tab and double-click the name of the table to view. This displays data from the table in Datasheet view arranged in columns and rows, similar to a spreadsheet. Datasheet views may be customized for printing or viewing by sorting, sizing, changing fonts, moving, hiding, or freezing columns. Navigating a Datasheet The record navigation buttons are located in the lower left hand corner of a datasheet or a form. You may also go to a specific record number by entering the record number in the record number box. PGUP or PGDN CTRL+Home CTRL+End F5 moves forward or back one page of records at a time go to first field of first record go to the last field of last record moves to the record number box where you can select record to go to Resizing columns/rows Resize rows or columns by positioning the mouse pointer on any border and dragging the border to the desired position. To resize a column to fit the data it contains, double-click the right border of the column heading. Rearranging, Hiding, and Freezing Columns To rearrange the order of the columns, select the column to move by clicking on the column heading and dragging to the desired location. To hide or freeze a column, choose the desired action from the Format menu, or right-click on the column and choose from the menu. D:\533579935.doc Page 3 Sorting data A datasheet is by default sorted by its primary key. To sort by another field, select the column(s) to sort by and click on either the ascending or descending sort button. Access can sort by more than one field if they are adjacent to each other. The sort order would be from left to right with the leftmost column being the primary sort. Note: you will only see the secondary sort if there are duplicate values in the primary sorted column. Other formatting features to change fonts and gridlines may be found on the Format menu. Adding Records New data records may be added through datasheet view or through use of a form. To switch from viewing all records to data entry mode, choose Records, Data Entry. To again display all records, choose Records, Remove Filter/Sort. All new records are added at the end of the datasheet. It is not necessary to save new records. A record is automatically saved as soon as you move to the next record. Editing Records Click in any field to edit the data in it. Any editing changes are saved as soon as you move to another record , or when you close the form or datasheet. When you are editing a record, a pencil symbol is displayed in the record selector on the left side of the current document. When you move to another record, the symbol disappears, indicating that your changes are saved. Undo The Undo command on the Edit menu changes depending on the procedure most recently completed. It may display Undo Typing, Undo Current Field/Record or Undo Saved Record. Note: as soon as you begin editing another record, apply or remove a filter, or switch to another window, your changes become permanent. Deleting Data You can either select fields, or an entire record to delete. To do this, select the data or record(s) to be deleted and press the DEL key (or choose Edit, Delete). Note: you will get one opportunity to change your mind. If you are deleting individual fields, then you will be able to use Undo. If you are deleting a record, there is noUndo. The record is permanently deleted from the database file and cannot be recovered. Copy/Move Data You can use the Cut, Copy, and Paste features under the Edit menu to move or replace data. Select the fields or columns you want to copy or cut. Choose Copy (or Cut) from the Edit menu. Select the destination field or fields, or switch to the Windows application you want to paste the data into and then choose Paste from the Edit menu. Note: you must select the same number of fields to paste into. For example, if you copy an entire record, you must select the fields for an entire record to paste into. D:\533579935.doc Page 4 Selecting Data Before you can copy, move, or delete data, you must first select it. Select data in a field: Click where you want to start selecting and drag across the data. Select the entire contents of a field: In a datasheet, click the left edge of the field; in a form, click the field's label. Select adjacent fields in a datasheet: Click the left edge of a field and drag to extend the selection. Select a column in a datasheet: Click the field selector at the top of the column you want to select. Select adjacent columns in a datasheet: Click the field selector for the first column you want to select and drag to the last one. Select a record: Click the record selector to the left of the record you want to select. Select multiple records: Click the selector of the first record you want to select and drag to the last. Select all records in a datasheet: Click the selector in the upper-left corner of the datasheet. Finding Data When you want to find a specific record or find certain values within fields, you can use Edit, Find to go directly to a record and to locate all records that meet your criteria. To find a specific value in a field: 1) click in the field where you want to search; 2) choose Edit, Find; 3) type in the value you wish to find and then choose a button to move to the matching record. Note: After you close the Find dialog box, you can find the next occurrence of the value you most recently searched for by pressing SHIFT+F4. This method of finding data can be used in either in a form or in the datasheet view of a table. Filtering Records Use Filters to specify the records that you want to appear in a datasheet or form view of a table, or to specify records in a query result set. Access provides three methods of filtering data. 1) Filter by Selection This method is fastest and simplest; you establish criteria by selecting all or part of the data in a field. Only those records matching the selected sample will be displayed. 2) Filter by Form Enter the filter criteria into a blank datasheet form of the table. You can either type in the criteria or select matching fields from a drop down list. D:\533579935.doc Page 5 3) Advanced Filter/Sort This is the most powerful and versatile filtering method. This method also enables you to sort at the same time. From the Advanced Filter Grid, you may choose to save your filter as a query for future use. To use this feature, choose Records, Filter, Advanced Filter/Sort. Apply a Filter Note: to apply a filter, click on the Apply Filter button. This is also the Remove Filter button. When the button is depressed, a filter is in effect; when it appears as raised, no filter is active. Note: You can also right-click with the mouse to bring up a quick menu where you can Filter by Selection, Filter Excluding Selection, Filter For (works like filter by selection except you type in the item to filter by), and Remove Filter/Sort. Filter/Sort Criteria (For Advanced Filter/Sort) To filter or sort records: 1) With a table or form open, choose Records, Filter, Advanced Filter/Sort. 2) Drag one or more fields to the Field row of the grid in the lower portion of the Filter window. Include only those fields for which you want to specify criteria or sort order. 3) Specify criteria, sort order, or both, under the field or fields included in the filter. 4) Click on the Apply Filter button to view records that match your criteria. Sort order: 1) You can sort records in alphabetic order or numeric sequence. 2) Click the Sort cell for the field you want to sort by; then click the arrow in the cell. 3) Select Ascending or Descending from the list. 4) To specify a sort order for more than one field, arrange the fields you want to sort by from left to right in the grid and repeat steps 2 and 3 for each field to be included in the sort. Sort criteria are evaluated from left to right on the query grid. Placement of the fields in the table is not relevant when using the grid. Selection Criteria: In the Specify Criteria field, either type an expression, or for assistance, open the Expression Builder. Do this by right clicking on the Criteria line and choosing Build from the menu. This will display the Expression Builder where you can click buttons for common operations or select references and other expression elements from a list. D:\533579935.doc Page 6 Multiple Criteria: To specify several criteria for just one field, use the 'And' and 'Or' operators. a) If you're looking for records that meet one criterion and another criterion, place both criteria on the same line. b) If you're looking for records that meet one criterion or another criterion, place the criteria on different lines. Specify two or more criteria for selection by using AND (criteria on same line) To specify OR, type multiple criteria on different lines. Operators: Access assumes a criteria of = unless you specify otherwise. Some commonly used operators and their meaning are listed below: > greater than < less than >= greater than or equal to <= less than or equal to Not (eliminates criteria from evaluation) Like (used with wildcard *) Between x and y (finds criteria in a certain range) Null (no value) EXAMPLES OF EXPRESSIONS: “CA” Value is CA >=”T” Value begins with the letters T through Z <D Values begins with letters A through C Is Not Null There is some value in the field <>CA or Not CA Every value except CA >=1/1/91 Date is on or after 1/1/91 Between 01-Mar-97 and 31-Mar-97 Date values are between those two dates Like “G*” Values which start with the letter G D:\533579935.doc Page 7