|
Optical Disc Publisher |
|
|
In this exercise, we will develop an application for a small CD publishing
company. The owner wants the prices to be calculated so a customer would get a
discount if he orders more. To attract customers and encourage them to order
more, she has decided to fix the prices so that the customer would pay:
|
- $20/CD if she orders less than 20 units
- $15/CD if she orders less than 50 units
- $12/CD if she orders less than 100 units
- $8/CD if she orders less than 500 units
- $5/CD if she orders more than 500 units
Practical Learning: Creating the Application
|
|
- Start Microsoft Access
- Replace the default file name with Optical Disc Publisher
- Click Create
- Close the default table without saving it
- On the Ribbon, click Create
- In the Forms section, click Form Design
- Save it as PriceEvaluation
- To use the needed spin button, in the Controls section of the
Ribbon, click the More
button and click ActiveX Controls
- From the list, click Microsoft Forms 2.0 SpinButton
- Click OK
- Design the form as follows:
|
Control |
Properties |
Form |
Caption: Optical Disc Publisher - Order
Evaluation
Navigation Buttons: No
Modal: Yes
Border Style: Dialog |
TextBox |
Label Caption: Number of
CDs/DVDs/BDs:
Name: txtQuantity
Format: General Number |
SpinButton |
Name: sbQuantity
Buddy Control: txtQuantity
Max: 10000 |
TextBox |
Label Caption: Unit Price:
Name: txtUnitPrice
Format:
Fixed |
TextBox |
Label Caption: Total Price:
Name: txtTotalPrice
Format: Fixed |
Button |
Use the Command
Button Wizard to create a button used to close the
form. Set its Caption to Close and Name it cmdClose |
|
- On the form, click the spin button
- In the Properties window,
double-click On Updated
- Click its ellipsis button
- Implement the event as follows:
Private Sub updQuantity_Change()
Dim Quantity As Integer
Dim UnitPrice, TotalPrice As Currency
txtQuantity = updQuantity.Value
Quantity = updQuantity.Value
If Quantity < 20 Then
UnitPrice = 20
ElseIf Quantity < 50 Then
UnitPrice = 15
ElseIf Quantity < 100 Then
UnitPrice = 12
ElseIf Quantity < 500 Then
UnitPrice = 8
Else
UnitPrice = 5
End If
TotalPrice = Quantity * UnitPrice
txtUnitPrice = CStr(UnitPrice)
txtTotalPrice = CStr(TotalPrice)
End Sub
- To allow the user to enter a quantity value, access the LostFocus
event of the txtQuantity text box and implement it as follows:
Private Sub txtQuantity_LostFocus()
updQuantity.Value = CInt(txtQuantity)
End Sub
- Test the application
|
|