PreviousTutorials and Guide to Samples (9.1 revision 1) Next

Lesson 2: Creating an Update Form

Show this topic in Library frames

In this section you will learn how to add another form to the project. This form will allow users to update information in the Student Browser, view additional information on students, and delete student records. The form will use multiple Pervasive.SQL ActiveX text buttons, option buttons, and command buttons.

After this lesson, you will be able to perform the following tasks:

Adding and Displaying Another Form

To add another form to your project:

  1. From the Project menu, choose Add Form. Click Open.
  2. Visual Basic adds a third form to the project.

  3. Change the form's Name property to frmStudentUpdate and its Caption property to Update Student Information.
  4. The frmStudentUpdate form will open when the user presses the Update Student Data button on the frmStudentBrowser form. When the user selects a specific student ID and then click the Update Student Data button, the form will display various details about the specific student.

  5. Switch over to the frmStudentBrowser form, and double-click the Update Student Data button to open its code in the Code Editor.
  6. In the Update Student Data button's click event, place the following code:
  7. frmStudentUpdate.Show 
    frmVAccessForm.VAccess1.Refresh 
     

    The first line displays the form, and the second line invokes the Refresh method which updates the data in all controls bound to the VAccess1 VAccess control. If the Refresh method were not used in this case, the controls you are about to place on the frmStudentUpdate form would be blank when the form appeared. The Refresh method updates the data in these controls according to the VAccess control's data buffer, causing the form to show the data as soon as it appears.

Placing Multiple Text Boxes

To add VATextBoxes:

  1. Place eight VATextBoxes on the frmStudentUpdate form so that they are in a vertical column.


  2. Set the VAccessName property of each text box to VAccess1 in the Properties window.
  3. Set the VAFieldName property of each VATextBox to one of the following names in this order:
    • ID
    • Tuition_ID
    • Transfer_Credits
    • Scholarship_Amount
    • Cumulative_Hours
    • Cumulative_GPA
    • Major
    • Minor

Adding Command Buttons

To add command buttons:

  1. Place three VACommandButtons on the frmStudentUpdate form, and set the Name and Caption properties of one button to cmdInsert, one to cmdUpdate, and one to cmdDelete.


  2. Set the VAccessName property of all three to VAccess1. As with the other controls, setting this property binds the control to the VAccess control.
  3. Set the VAOperation property of the Insert button to 2-Insert, the Update button to 3-Update, and the Delete button to 4-Delete.
  4. The VAOperation property assigns a Pervasive.SQL operation to the VACommandButton to be performed when the button is clicked. This operation occurs after any code in the Click event.

    You now have buttons on the form which will add new student records to the database, modify existing student records, and delete student records.


    Note
    Most of the fields are the same in both forms, though each form has fields that the other does not. The fields that are the same on both forms are the ones the user can update.

    You will probably want to use Visual Basic Label controls to identify each of the VATextBoxes on the form and to arrange the controls neatly on the form. The form should be similar to the following figure:

    Figure 6-11-Completed Update Student Information Form



Testing the Application

To test the features you added in this lesson:

  1. Save your work and run the application.
  2. Scroll through the records on the frmStudentBrowser form and then click the Update Student Data button.
  3. The Update Student Information form opens and displays the fields for the specific student selected in the list. Notice as you scroll through the list on the Student Browser window how the data on the two forms remains in sync.

  4. Enter new data into the VATextBoxes on the Update Student Information form and then click the Insert, Update, and Delete buttons to add, modify, or delete records.

Chapter contents
Publication contents

Prev topic: Lesson 1:  Creating a Data Browser
Next topic: Lesson 3:  Joining Records from Two Tables