473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdTotalPrice_Click()
  2.  
  3. Dim TotalPrice As DAO.Recordset
  4. Dim db As Database
  5.  
  6. Set db = CurrentDb
  7. Set TotalPrice = db.OpenRecordset("qryOrderLine", dbOpenDynaset)
  8.  
  9. TotalPrice.Edit
  10.  
  11. Do While Not TotalPrice.EOF
  12.  
  13. If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
  14. totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total Price").Value
  15.  
  16. End If
  17. TotalPrice.MoveNext
  18. Loop
  19.  
  20. txtTotalPrice = totalpricefororder
  21.  
  22. End Sub 
I have no idea where to start with this discount and my understanding of code is not the best. Please help
Attached Images
File Type: jpg Untitled-5.jpg (45.6 KB, 257 views)
Mar 29 '11 #1
5 4156
kadghar
1,295 Expert 1GB
mmm, maybe you can exit the sum before you enter the last element, so it wont be added:

Expand|Select|Wrap|Line Numbers
  1. Do 
  2.  
  3. If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
  4. totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total Price").Value
  5.  
  6. End If
  7. TotalPrice.MoveNext
  8. 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:

Expand|Select|Wrap|Line Numbers
  1. Dim myCount as Integer
  2. Do While Not TotalPrice.EOF
  3. myCount = myCount+1
  4. if myCount = 5 then
  5.      myCount=0
  6. Else
  7.      If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
  8.      totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total     Price").Value
  9.      End If
  10. End If
  11. TotalPrice.MoveNext
  12. Loop 
HTH
Mar 30 '11 #2
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.
Apr 14 '11 #3
kadghar
1,295 Expert 1GB
instead of just putting Mycount=0 each 5 items, also put a zero priced one.
Apr 15 '11 #4
the code doesnt work. it just breaks my subform
Apr 17 '11 #5
kadghar
1,295 Expert 1GB
Mmm, it shouldn't. It might seem like this:

Expand|Select|Wrap|Line Numbers
  1. Dim myCount as Integer
  2. Do While Not TotalPrice.EOF
  3. myCount = myCount+1
  4. if myCount = 5 then
  5.     myCount=0
  6.     If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
  7.      totalpricefororder = totalpricefororder + 0
  8.      'or any other line that helps you keeping a record, e.g.
  9.     'TotalPrice.Fields.Item("Total Price").Value = "0.00"
  10.      End If
  11. Else
  12.      If (TotalPrice.Fields.Item("Sales ID").Value = Me!txtSaleID) Then
  13.      totalpricefororder = totalpricefororder + TotalPrice.Fields.Item("Total Price").Value
  14.      End If
  15. End If
  16. TotalPrice.MoveNext
  17. 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.
Apr 18 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Justin Koivisto | last post by:
OK, here's one of the rare times where I call out to all of you. ;) I need to implement a promotional discount code module into osCommerce 2.2 Milestone 2. I've never created an OSC module...
1
by: Luke Ward | last post by:
Hi When server side errors occur I need to do a round trip, go back to the page preserving the user entered data, and also inform the user of the error. The page preserves things in textboxes,...
4
by: pauldepstein | last post by:
I am writing code to price some financial options using recursive functions. It compiles but I get a runtime error which is caused by a memory violation. The problem is that the code is much...
2
by: gizelle2101 | last post by:
I've read the articles, but nothing is working. My database just lists jewelry by type and gems. I want to pull out the most expensive piece and the least expensive piece in one query. <code> ...
25
by: cristip3001 | last post by:
Hi, I'm a newbie in Access and SQL. I am trying to write a query in Access that returns the sum of values on a column. The query works fine, the only problem is that if there are no values it return...
3
by: gator6688 | last post by:
I have to write a program that asks for a cost-per-item, number of items purchased, and a discount rate. Then it should calculate the total cost, tax due, and amount due. I have to use the...
5
by: omar999 | last post by:
hi guys - okay I've already asked this question in the xml section here but I'm not having much luck. I have an xml file which we send to a 3rd party company - the 3rd party company then utilises...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.