Discount code on a 5 items for the price of 4

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdilSaumtally
    New Member
    • Mar 2011
    • 16

    Discount code on a 5 items for the price of 4

    I currently have have an form with a subform to manage a transaction. I have a button that calculates the total price of the order for all items purchased. (picture in attachment).

    I am wondering whether it would be possible to add in a discount for 5 of any items (e.g 3 or item 1 and 2 of item 2); or whether having a discount for 5 of item 1 and 5 of item 2 would be easier to code.

    The code that i currently have to calculate the total price for all items is:
    Code:
    Private Sub cmdTotalPrice_Click()
    
    Dim TotalPrice As DAO.Recordset
    Dim db As Database
    
    Set db = CurrentDb
    Set TotalPrice = db.OpenRecordset("qryOrderLine", dbOpenDynaset)
    
    TotalPrice.Edit
    
    Do While Not TotalPrice.EOF
    
    If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
    totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total Price").Value
    
    End If
    TotalPrice.MoveNext
    Loop
    
    txtTotalPrice = totalpricefororder
    
    End Sub
    I have no idea where to start with this discount and my understanding of code is not the best. Please help
    Attached Files
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    mmm, maybe you can exit the sum before you enter the last element, so it wont be added:

    Code:
    Do 
     
    If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
    totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total Price").Value
     
    End If
    TotalPrice.MoveNext
    Loop While Not TotalPrice.EOF
    Of course this will always remove the last item. Or you can put an integer to count things inside the loop so you can avoid summing each 5th item:

    Code:
    Dim myCount as Integer
    Do While Not TotalPrice.EOF
    myCount = myCount+1
    if myCount = 5 then
         myCount=0
    Else
         If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
         totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total     Price").Value
         End If
    End If
    TotalPrice.MoveNext
    Loop
    HTH

    Comment

    • AdilSaumtally
      New Member
      • Mar 2011
      • 16

      #3
      sorry about the loonnng reply... been away. i need to be able to keep DAO recordset in this so i can get the mark for it.

      Comment

      • kadghar
        Recognized Expert Top Contributor
        • Apr 2007
        • 1302

        #4
        instead of just putting Mycount=0 each 5 items, also put a zero priced one.

        Comment

        • AdilSaumtally
          New Member
          • Mar 2011
          • 16

          #5
          the code doesnt work. it just breaks my subform

          Comment

          • kadghar
            Recognized Expert Top Contributor
            • Apr 2007
            • 1302

            #6
            Mmm, it shouldn't. It might seem like this:

            Code:
            Dim myCount as Integer
            Do While Not TotalPrice.EOF
            myCount = myCount+1
            if myCount = 5 then
                myCount=0
                If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
                 totalpricefororder = totalpricefororder + 0
                 'or any other line that helps you keeping a record, e.g.
                'TotalPrice.Fields.Item("Total Price").Value = "0.00"
                 End If
            Else
                 If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
                 totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total Price").Value
                 End If
            End If
            TotalPrice.MoveNext
            Loop
            Perhaps it didn't work because I left some spaces in your item's name. Never the less, I'm just giving you some ideas of how a soulution could look like. You're the one who knows your code and your requirements.

            Comment

            Working...