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:
- Fix our Quantity Received problem.
- Add a button to save our record.
- 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.
- Click once in the gray
non-working part of the window (see below).

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

Click
Code Builder from the list and click the OK
button.
- The Class Module window appears. This
is the area where you do the programming in.

- Type in:
[Quantity
Received] = 0.
This will reset the field every
time the record is changed.
- 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.
- In the Toolbox, click
the
button.
The mouse pointer will change to
.
- Click once just below
the Retail Price field.
- The Button Wizard will
begin.
- 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.

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

- 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.
- Click the SaveButton
object.
- If the Properties box
is not showing already, click the Properties
button on the toolbar.
- Scroll down through
the list until you come to "On Click".
- Click once on the On
Change box and click the
button.
- 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.
- 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.
- In the Toolbox, click
the
button.
The mouse pointer will change to
.
- Click once just below
the Total Quantity field.
- The Button Wizard will
begin.
- 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.

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

- 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.