Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatically add discount % to combo box based on date difference

Status
Not open for further replies.

neerajam

Technical User
Mar 4, 2002
23
0
0
US
I am creating an order entry form. My customer gets a discount based on the following:

2 year program discount: year 1 = 2%
year 2 = 4%
3 year program discount: year 1 = 2%
year 2 = 4%
year 3 = 6%
4 year program discount year 1 = 2%
year 2 = 4%
year 3 = 6%
year 4 = 8%
What I was contemplating doing was to have a date picker control with the start date, today's date, difference between the 2 dates, check to see if it is greater than 2,4,6,8 years and automatically generate the value in the combo box. The big question is how. I tried but got a lot of errors and thus the request.

Your help would be greatly appreciated.

Thanks.
 
You can get your date difference something like this...

'dtpOrder is the name of the date time picker
Private Sub dtpOrder_Exit(Cancel As Integer)
Dim intDiff As Integer

'calculate the difference in years between now and
'selected date
intDiff = DateDiff("yyyy", dtpOrder.Value, Now())

'select action depending on
'years elapsed
Select Case intDiff
Case Is = 2, 3
'2 or 3 years elapsed
'set discount to whatever
Case Is = 4, 5
'4 or 5 years elapsed
'set discount to whatever
Case Is = 6, 7
'6 or 7 years elapsed
'set discount to whatever
Case Else
'if none of the above apply
'set default here
End Select

End Sub

this is not exactly what you want ie. cases will need to be changed.

Also, do you just want to make a selection in your combo based on the result of the case??

There are two ways to write error-free programs; only the third one works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top