FIT 100

Lab 13:  More Microsoft Access and Relational Databases

Creating Forms for Data Entry

Winter 2002

.pdf version of this document

 

Reading for Lab:

·         Review Chapter 20 of Fluency with Information Technology:  Foundations and Fundamentals of Information Technology

Working With Forms in Access 2

Create a Form using the Form Wizard. 2

Creating a Form Using Design View. 3

Displaying Data from One Table to Help Add Data to Another: 
Adding Instances to tblStudent 7

Adding Other Controls Error! Bookmark not defined.

 

Introduction:

In today’s lab we will look at the presentation layer:  creating forms for users to input data and receive data output. (See the previous Lab for a brief description of all three levels involved in a complete Relational Database Management System)

 

Presentation Services

The interfaces created to allow users of the Database system the ability to enter data and to view output of data.  A Form is the typical interface used for input and output of data that is retrieved by a Query.  There are other interfaces in Access such as Reports and Data Access Pages, but you will only be dealing with Forms for the first part of Project 3.

 

Objectives:

  1. To connect the abstract concepts of Entities, Attributes and Rows (Tuples) in the Relational Database Model with the corresponding objects in Access that are concrete representations of those concepts.
  2. To become familiar with MS Access, one of many different Relational Database Applications.
  3. To create forms that will allow a user to add data to tables using a friendly interface.

 

TO BEGIN: 

1.      Download a copy of your database (.mdb file) from the previous lab to the desktop from Dante and open it. [The illustrations below may show the file as Lab15.mdb; use Lab12.mdb or whatever else you actually named the file as in the previous lab.]

If your database was not closed when you tried to ftp it after the last lab, you will have an empty file.  If this happened, you will need to work through the previous Lab to recreate it.

 


Working With Forms in Access
Today’s lab allows you to work with a familiar object, the Form.  In Access forms are used for presentation in a manner similar to their use in Visual Basic. Both are intended as a way to present data of some kind to a user in a way that is intuitive and helpful (although not every form is successful in this endeavor!).

 

The first form will be created using a wizard. The second and third will be created just in design view. In addition, you will add combo boxes on one form in order to view data from two different tables as we add data to a third.

 

2.     Create a Form using the Form Wizard

 

  1. Create a form to add Major instances (rows of data) to the Major table.  Go to the Forms window and create a form for the Major table using the form wizard.

 

  1. Select Table: tblMajor from the available fields and move all the attributes over to the right to the selected fields.

 

 

  1. Choose a layout (Usually Columnar or Justified is the nicest looking)

·         Click Next

·         Choose a style

·         Click Next

  1. In the last window, give a name to the form.  Call it frmMajor to distinguish it from the table Major.  Click finish and the form will open up, ready for you to add data.

  2. Using frmMajor, add the following Majors:

 

INFO

CSE

BIOL

CHEM

PHYS

SPAN

ART

HIST

 

 

  1. Save the form layout and close the form.  Go to the Major table.  Are the records you just added through the form in the table?  Good!

 

3.     Creating a Form Using Design View

  1. Create a form in design view to add data to the Advisor table.  Name it frmAdvisor.

  2. To add the fields to the form, simply access the Form properties

·         Right click on the form title bar, select Properties

·         Make sure the Form object is selected in the window

·         Select as the record source the Advisor table from the list.

 

 



  1. A window with a list of the attributes for the Advisor table should pop up.  If it doesn’t:

·         Go to View>Fields List on the Menu bar

 

 

  1. Drag and drop the attributes onto the form in an arrangement that suits you.

 

 

  1. Switch to Form View and see the how it looks.

4.     Manipulate field properties in Design View

  1. Switch back to the design view by clicking the icon in the upper left corner:

 

  1. Select one of the fields shown in the form.

  2. Right click and go to the properties of that field.



  3. Explore the properties and change a format based property, such as Caption or BackColor.

     



  1. Now adjust the back color of the Form, then look at it in Form View

 

 

  1. Using frmAdvisor, add the following Advisor Names and Department:

Mel Oyler from Informatics

Alan Borning from Engineering

John Cusak from Art

Vitoli Demetrio from Modern History

Garbonzo Bean from Physics

 

Go to the Advisor table.  Look at the records you just added through the data entry form.

5.     Displaying Data from One Table to Help Add Data to Another:  Adding Instances to tblStudent

Now we’ll do something a little different:  create a form that adds data to the Student table, but it will display data from Major and Advisor tables.

  1. Go through the 5 again, but use the Table: tblStudent to add all the fields. 

 

  1. Save the form as frmStudent.  You now will have a form that may look different from this, but all the attributes should be listed:

 



  1. Switch to the design view by clicking the icon in the upper left corner:

 

 

  1. In design view, extend the borders of the form and the form footer to give you some layout room.  Notice the form has some similarities to the form setup from Visual Basic.  Access uses a subset of Visual Basic called VBA and works with the same type of Integrated Development Environment (IDE).

 

 

  1. Add two combo buttons to the form.  One combo button will be used to display the contents of the Major table.  The other will display the contents of the Advisor table.

 

  1. From the tool box on your screen, select the combo box object.  Add the first combo box to the form here in the same way you added controls to your forms in VB.

 

 

Once you place the combo box control on your form, a combo box wizard window will come up to walk you through the process.

 

Select the following options from each screen and then click Next:

 

  1. Have the combo box look up values from a table
  2. Select the Major table for the table that will provide values for the combo box.
  3. Move all available fields over to the selected fields window.
  4. Make sure the “Hide key column” box is checked
  5. Store the value in the “MajorID” field of the Student table (those are the options in the drop down menu)
  6. Leave the name the combo box is given and click Finish.

 

You will return to design view.  There is now a combo box and label in the form.  The label can be deleted (the combo box should line up across from the other Major label and text box).

 

 

 

  1. Switch to Form view and look at the values that are in the combo box.  Tres cool, no?

 

 

  1. Return to Design View.  Add another combo box just across from the AdvisorID text box.

  2. Select the following options from each screen and then click Next:

 

·         Have the combo box look up values from a table

·         Select the tblAdvisor as the table that will provide values for the combo box.

·         Move ONLY the AdvisorID, Lname and Department from the available fields over to the selected fields window.

·         Make sure the “Hide key column” box is checked

·         Store the value in the “AdvisorID” field of the Student table (those are the options in the drop down menu)

·         Ignore the name option for the combo box and click Finish.

 

  1. Return to design view.  There is now a combo box and label in theform.  Delete the label.  (Ask your Instructor if you aren’t sure)     

 

  1. Start moving through the records you have already created in Form View. 

    You should see the number value of the Advisor in the text box for Advisor ID and the name and department of the person that goes with that number appears in the combo box on the right. 

 

We have set up the combo box so that it displays the text values for us to see, but it will store the corresponding key value in the Student table in the attribute AdvisorID.  That stored value will be referred to as a foreign key in the Student table.

 

  1. Since we deleted the original Major attribute and that held text earlier in the lab, let’s now add a major for the students in the table.  Use the combo box to select a Major. Notice the corresponding key value is stored to the left.

  2. Add a total of 6 student records using the form.  Give the students a major and an advisor.

 

6.     Add a List Box to the Form

  1. Add a list box to the form.  This list box will be used to access a particular record using only the last name field

 

  1. From the tool box on your screen, select the list box object (also known as a control).  Add the list box to the form here by clicking and dragging it to the size you want on the screen.

 

Once you place the list box control on your form, a wizard window will come up to walk you through the process.

 

Select the following options from each screen and then click Next:

 

  1. Have the list box find a record based on the value selected.
  2. Click Next
  3. Select the field to use from the student table [LName].
  4. Move the field over to the selected fields window.
  5. Click Next.
  6. By Default, the Key field is also added if you did not choose it.  Make sure the “Hide key column” box is checked.
  7. Name your list caption “Student Last Name”.
  8. Click Finish.

 

You will return to design view.  There is now a list box and label in the form. 

 

 

 

  1. Switch to Form view and look at the values that are in the combo box.  Tres cool, no?

 

         

 

  1. Start moving through the records you have already created by selecting a name from the list box. 

7.     Refreshing the Form and Closing the Form

  1. Go to design view and add two command buttons to the form.  One will refresh the page and the other will close it when a user is done adding data. 

 

  1. Select a command button control and place it on the form in the upper right hand corner.

 

  1. When the Command Button Wizard comes up, select Form Operations from the Categories column and Refresh From Data from the Actions column and click next:

 

 

  1. Choose either a picture or text for display on the button and click next:

 

 

  1. Name the button cmdRefresh and Finish.

 

  1. Save your form.  Switch to Form View, add an additional record and press the Refresh button.  Does the list box get updated?

 

  1. Now go through the same process but select the correct operation to close the form when the button is clicked.

 

  1. Save your form.  Switch to Form View and press the exit button.  Does the form close?

***A quick note about file size:***

 

As you start working on your project, you will create forms.  You will make mistakes and decide to delete forms and other objects from the database.

 

In other applications, this would usually mean your file gets a little smaller.  It is NOT that way in Access.

 

Access “remembers” all the different forms and command buttons, etc that you create - even after you delete them.  If you don’t occasionally do a little “house cleaning”, your database file will grow immense!

 

To clean up your database and decrease the file size after you have been working in it for a while, compact and repair the database:

 

Tools>Database Utilities>Compact and Repair Database…

 

Do this to keep the database size manageable (or the turn-in program may have difficulty with it).

 
 


 

 

 

 

 

 

8.      Close your database and FTP the .mdb file (remember, you created it in the previous Lab) to your Dante account if you don’t already have it on disk.  We will use it again for the next lab.

 

WHEW!!!! You’ve made it through another lab!  Only a few more to go!!!!!