- Start Microsoft Access and create a blank database
- Save the database as CD Publisher
- Start a new form in Design View. Save it as PriceEvaluation
- To use the needed spin button, on the Toolbox, click the More
Controls button
- From the list, click Microsoft UpDown Control, Version 6.0 and click
somewhere on the form
- Design the form as follows:
|
Control |
Properties |
Form |
Caption: CD Publisher - Order
Evaluation
Navigation Buttons: No
Modal: Yes
Border Style: Dialog |
TextBox |
Label Caption: Number of CDs:
Name: txtQuantity |
UpDown |
Name: updQuantity
Alignment: Right Align
Buddy Control: txtQuantity
Max: 10000 |
TextBox |
Label Caption: Unit Price:
Name: txtUnitPrice
Format: Currency
Decimal Places: 2 |
TextBox |
Label Caption: Total Price:
Name: txtTotalPrice
Format: Currency
Decimal Places: 2 |
CommandButton |
Use the Command
Button Wizard to create a button used to close the
form. Set its Caption to Close and Name it cmdClose |
|
- Access the Code Editor or Microsoft Visual Basic. In the Object
combo box, select updQuantity. In the Procedure combo box, select Change
- Implement the Change 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
|
|