CD Publisher

Introduction

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
 
  1. Start Microsoft Access and create a blank database
  2. Save the database as CD Publisher
  3. Start a new form in Design View. Save it as PriceEvaluation
  4. To use the needed spin button, on the Toolbox, click the More Controls button
  5. From the list, click Microsoft UpDown Control, Version 6.0 and click somewhere on the form
  6. 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
  7. Access the Code Editor or Microsoft Visual Basic. In the Object combo box, select updQuantity. In the Procedure combo box, select Change
  8. 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
  9. 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
  10. Test the application
 

Home Copyright © 2004-2007 FunctionX, Inc.