Step Nine - Price and Quantity Form (con't)

We are going to continue to build our Price and Quantity Form.

In this section we will:

  1. Fix our Quantity Received problem.
  2. Add a button to save our record.
  3. Add a button that will close the form.

Initializing a Field

Currently the problem with the Quantity Received field is that there is no value in there when we first view the form. Also, the value we do enter is being cascaded across each record we look at. Here is how we can initialize a field every time you switch to a different record.

  1. Click once in the gray non-working part of the window (see below).

  2. If the Properties box is not showing already, click the Properties button on the toolbar.
  3. Scroll down through the list until you come to "On Current".
    This control is executed every time you switch to a different record.
  4. Click once on the On Change box and click the button.
  5. The following window appears:

    Click Code Builder from the list and click the OK button.

  6. The Class Module window appears. This is the area where you do the programming in.

  7. Type in:

    [Quantity Received] = 0.

    This will reset the field every time the record is changed.

  8. Close the Class Module window by clicking the button in the window.

Switch to the Form View and see what happens.

As you can see, the value 0 appears in the Quantity Received field and now the Total Quantity field can be calculated and has a number in it.


Adding a "Save" button

We are now going to add a button to save the changes we do to the record.

  1. In the Toolbox, click the button. The mouse pointer will change to .
  2. Click once just below the Retail Price field.
  3. The Button Wizard will begin.
  4. The first step allows you to pick the type of action to be performed when the button is clicked. In the Categories section, click Record Operations. In the Actions section, click Save Record. Click the Next button.

  5. This step allows to select if you want a picture in your button or text. Click the Text option. Click the Next button.

  6. This step allows you to assign a name for the button. This the Name field you will find in the Properties window. Type in "SaveButton" and click the Finish button.

This button will now save any changes that have been made (CostPrice). But what about Total Cost. This field is not a field in our table. This new value has to be assigned QuantityInStock to have correct numbers.

  1. Click the SaveButton object.
  2. If the Properties box is not showing already, click the Properties button on the toolbar.
  3. Scroll down through the list until you come to "On Click".
  4. Click once on the On Change box and click the button.
  5. You should see some code there already. Access has automatically generated this code as you were using the Button Wizard. Click the line above the "DoCmd......" line. Type in:

    [QuantityInStock] = [TotalQuantity] <press return key>
    [QuantityReceived] = 0

    This will assign the new value to QuantityInStock before the record is saved and initialize the QuantityReceived field.

  6. Close the Class Module window by clicking the button in the window.

Adding a "Close" button

We are now going to add a button to save the changes we do to the record.

  1. In the Toolbox, click the button. The mouse pointer will change to .
  2. Click once just below the Total Quantity field.
  3. The Button Wizard will begin.
  4. The first step allows you to pick the type of action to be performed when the button is clicked. In the Categories section, click Form Operations. In the Actions section, click Close Form. Click the Next button.

  5. This step allows to select if you want a picture in your button or text. Click the Text option. Click the Next button.

  6. This step allows you to assign a name for the button. This the Name field you will find in the Properties window. Type in "SaveButton" and click the Finish button.

You now have a button to close the form.


Click the Save button or select File, Save from the menu.

Change to Form view and test your new buttons.

If everything works thats it for now!! Good luck with your projects.


[Back]

[Home]