Maintaining a Database Using the Design and Update Features of Access

Total Page:16

File Type:pdf, Size:1020Kb

Maintaining a Database Using the Design and Update Features of Access

Access Project 3

Maintaining a Database using the Design and Update features of Access

Maintaining the database  adding/deleting records  updating records  deleting more than one record at a time  updating more than one record at a time

Restructuring the database  Adding new fields  Changing the characteristics of a field  Removing fields  Creating an index, which is used to access records ordered by different fields than the primary key

Adding Records  Using Form View to add records  Open Database, then select form. Click on >* button at bottom of form to add new record  Or: Click on Form, right click on desired form, and select Open from shortcut menu

Searching for a Record  Enter criteria. The database will search for the first record that satisfies the criteria.  Searching Client Number FL93 o Open Form that relates to the Client table o Click First Record button on Form to start the search at the top of the database. The First Record button is located at the bottom of the form |< o Select Client field (or the field used to search) o Click the Find Icon (binoculars) on tool bar o Enter FL93 in the Find What text box o Click the Find Next button, and then Close the window. Or, leave the Find window open and click Find Next

Update a Record  Use the Form to access a record, and then enter new/corrected information

Switching between Form View and Data Sheet view  Select the View Icon at the left of the tool bar  Use the drop down menu to select Data Sheet or Form View Filters  Currently in Datasheet view all the records are displayed. Specifying a filter will eliminate unwanted records from the datasheet view  To Filter Records (Filtering By Selection shown here) o Open Database in Datasheet view o Click on Field to use as filter (Zip Code would select all records with that zip code) o Click on the Filter Icon (It looks like a funnel) . Records that match the Zip Code chosen above will be displayed. o Click on the Remove Filter Icon to remove filter and restore all records to the datasheet view.  Using Advance Filters/Sort o Open table in Data Sheet view o Enter: Records/ Filter/ create the Filter (same process as creating a query) o Click the Filter Icon to display records o Click the Filter Icon again to return to datasheet view

Deleting Records  Locate the record and then hit the Delete key  Locate record in datasheet view (search as shown above if necessary)

Changing the structure of a Database AC 126  Adding new fields, deleting fields, and changing the properties of existing fields will be discussed in this section  Changing the size of a field o Select appropriate table, Right click and select design view o Select field to receive changes, make changes  Adding a new field: Client Type will be added, holding EDU, MAN, SER o Open Table in Design View o Point to field after the field where new field is to be inserted o Select Insert Row Icon and click to insert a new row o Delete Row Icon will delete selected row

Changing the Appearance of a Datasheet  Resizing Columns o From the datasheet view, go to heading of column to be resized and position the cursor on the right side of the heading cell. Slide the cursor to the desired position (cursor turns into a double headed arrow with line down through the middle). o Place the cursor above the column to be resized, at the right so the cursor changes form, then Double Click (Best Fit) will decrease/increase size automatically

Making Changes to Several Records at once (such as changing the Area Code for all records in the Rochester area) Using an Update Query AC136  Fill in multiple records with a common value rather than updating each record individually o Select Table to be updated o Select New Object Icon, use drop down menu to select query o Select Design view o Right Click on Area at top of window, and select Query Type from short cut menu o Select Update Query o Select Field to be updated from list of fields o Enter new value and criteria if any o Run ! the query o Click yes to are you sure message box

Using a Delete query is the same as above, except select Delete Query

Creating Validation Rules

Validation rules specify certain values that are allowable for entries in fields of a database. When the user attempts to enter an invalid number, Access will inform the user of the error and possibly suggest new entries

Required fields are fields that must be entered when a new record is added/updated. These can be specified as well as the validation rules. The Primary Key field is an example of a field that must be entered by the user. If this field is left blank, or if this field is a duplicate to another primary key, then an error message is displayed. The exception to this rule is if the system is generating its own primary keys automatically.

Required Field  In design view select row, then in Field Properties list below, place Yes in Required field

Default Values  Entered automatically when the new record is to be entered. You may overwrite this entry.  Place = Value in the Default Field: = VT would automatically place VT in the State field Validation Rules Specifying a range AC140  Select the field to perform the testing upon  In the property box below enter the Validation Rule. Here are some examples o >=0 and < 2000 to ensure a numeric value is in range from zero up to but not including 2000. o =MA or = CT to ensure a two character field equals either MA or CT Specifying Text to display when an error occurs  In the field: Validation Text enter the statement: Must be MA or CT This text will appear when the user enters an invalid state.  By default, if you have stated that the field is to be two characters wide then the user will not be able to enter more than two characters.

Display Specifications Specifying the display of values in a table  Access can be directed to format a field value despite the way it has been entered in the database. For example, the description of an item can be displayed in lower case despite how it was entered.  Select a table, then Right-click and enter Design View  Select the field to format  In the format field below, enter < This symbol will convert all characters in the selected field to lower case, despite how they were entered. o > in the Format field will convert all characters to upper case

Using a Lookup Field (see page 147) A lookup field will supply the user with a dropdown menu of possible values for a field. This is used when entering the data for that field.  Select Table/ choose Design View  Select field, then use the Drop down menu from the field Type  Select Lookup Wizard  Select Option: “I will type in the values that I want.”  Enter the values in the table that is provided, using the down arrow key to select the next row.  Click the Finish key when all values have been entered.  To Use the Lookup Field o When entering text use the drop down menu to select values

Referential Integrity AC 150 Using the Ashton James Database as an example, the two tables must have referential integrity with respect to the Trainer Number. Any Trainer number that is placed in the Client table must have a corresponding Trainer number in the Trainer Table. Also, if referential integrity is in place, you will not be able to remove a record from the Trainer table if that trainer is currently listed in the Client Table. The Trainer number is a primary key in the Trainer table. Since the same trainer number is used in the Client table, it is called a foreign key to the Client table. There is a One-to-Many relationship between the two tables. Starting with the Trainer table, One trainer is matched (related) to several records in the Client table. Starting with the Client table, One technician as part of one record is matched with only one record in the technician table. Create Referential Integrity  Database is in Table view  Click on Relationships Button in menu  If necessary, right click window and choose Show Table to show list of tables to be related  Click the tables to be related  Important: Starting with the table where the related field is the primary key, click and drag the primary key field from primary key field to other table, where the key is the foreign key (that is, it may appear more than once in the second table)  IMPORTANT: Click the Box to select: Enforce Referential Integrity  ALSO: The assignment requests you to Click the Box next to: Cascade Update…  Save the database. You may be asked if you want to check existing data for referential integrity. Click Yes

Using Subdatasheets Once you have established referential integrity between two tables, it is possible to display the two tables at the same time. Open the table with the primary key that is related to another table. In front of each record is a ‘+’ symbol. Clicking on the ‘+’ symbol will cause the related records in the second table to be displayed.

Changing the order of records Open the table in Datasheet view. Click the field that is to be used in ordering, then select A-Z button for example. This will order the records alphabetically using the selected field. You can choose to change the database or not when you exit the datasheet view. Ordering on more than one field. These two fields must be next to each other. Click on the field name of the first field, and then holding down the shift key, click on the title of the next field (it must be adjacent to the first). Now choose the order (A-Z for example). The data will be sorted alphabetically by the first field, and then if there is a tie, the second field will be the tie breaker. It is usually easier to set up a query to perform this work. Creating and Using Indexes An index to a database is an additional table that lists the desired field with the position of the record that relates to that field. These additional tables are used to quickly display a database in a specific order, rather than having to sort the records each time. The additional table s also allow quick access to records. In the Client database the records are sorted by Client Number, so listing the entries by Client Number is quick and easy. But to list the records sorted by Zip Code would require the database to sort all records first, then list them (for example listing them to a report). Access makes use of an additional table that lists the entries of the database sorted by client Name (see page A 157). Access uses this table to access records sorted by Name. The first entry indicates that the record with the “lowest” Name is located in position 1. Access quickly accesses this record and prints it out. It then goes on to the next listing and prints record 3. This process is usually faster than sorting all the records by zip code and then listing them, especially when working with very large tables.

Creating a single field index  Open the table in design view  Select the single field to create the index  In the Field Property window below select Indexed and use drop down menu to select either Yes with duplicates allowed , or Yes with No duplicates

Creating an index with multiple fields  This requires use of the New Object Wizard and is shown on page AC160. We will not be using this feature for this course.

Recommended publications