VBA code

Cam

New member
Local time
Tomorrow, 04:45
Joined
May 8, 2014
Messages
4
I'm trying to write a code for following senario,

A customer may be offered "rebates" each time the machine is used per month,
Example
1-200 $0.70
201-500 $1.00
500-9999 $1.20
If a customers machine did 525 transactions in the month,
This means for the transaction upto 200 for the month they will receive $0.70 a get (200 x $0.70 = $140) the next 300 transactions (201-500) will get $1.00 (300 x $1.00 = $300) and 25 transactions (501-525) will get $1.25 (25 x $1.25 = $31.60) there the customer will earn $140 + $300 + $31.60 = $471.60.


my code

Private Sub Rebate_KeyPress(KeyAscii As Integer)

Dim result As Integer

Select Case result

Case Form_CustomerF.Total <= 200

result = Form_Customer.Total * 0.7

Form_CustomerF.Rebate = result

Case Form_CustomerF.Total >= 201 And Form_CustomerF.Total <= 500

result = Form_Customer.Total - 201 + 140

Form_CustomerF.Rebate = result

Else

result = Form_Customer.Total - 501 * 1.2 + (300 + 140)

End Sub

so what this does is examine data from form and inputs the value to rebate field. Im not sure why its not working and im losing hair :banghead:
Any help will be appreciated :)
 
Why the choice of KeyPress event? Could you not calculate this in Queries?
 
Whenever you post a question here about something you have tried, saying it 'doesn't work' is sort of worthless. The mere fact you are posting here implies it 'doesn't work', if it did work you wouldn't be posting here. We need more than those two words. What does 'doesn't work' mean? Getting an error message? Unexpected results? No results?

My guess is its the last one. Look over your code, how are you to know it 'works'? You haven't told it to do anything you can check. You simply set the result variable to a value and then never do anything with it. You need to do something with result--either have put into a form object, msgbox it out or turn the Sub into a Function and have it returned. You do nothing with your calculated value.

On second glance, I see that it does do something with the value, but only if the input result is less than or equal to 500. That last Else only puts the result in result and doesn't put it on the form. What happens when you input 100?

Also, you never end the Select. Check out this documentation for it: http://www.techonthenet.com/excel/formulas/case.php
 
Last edited:
Ok thanks for the tip kinda new to VBA and forums,
Will make try to be clear nxt time
 

Users who are viewing this thread

Back
Top Bottom