How do I make a date increase by a set number of years

Ice Rhino

Registered User.
Local time
Today, 18:12
Joined
Jun 30, 2000
Messages
210
I have a warranty field that I am trying to create. I want the value of this field to be

Date_Purchase (Date/Time) + Warranty_Period (Number) = Warranty_Expires

e.g. 17/08/02 + 2 (years) = 17/08/04

I would like to do this calculation at the point of entering the record

Anybody?
 
Use DateAdd() as shown below.

Private Sub Warranty_Expires_AfterUpdate()
Me.Warranty_Expires = DateAdd("YYYY",2,Me.Date_Purchase)
End Sub
 
Thanks, I will give that a whirl

Toni
 
Is that code doing the right thing?

THe only reason I ask is that it does not appears to be work, albeit I have done what you said

I was looking to add the date of purchase to one box, the amount warranty (in years) to another box, and then code take over and populate the 3rd box with the 1st box's date, plus the warranty period figure and come up with the answer

For example

I enter in Box 1 - '18/08/02'
I enter in Box 2 - '2'
The code will populate box 3 with - 18/08/04

Or did I miss something in the example that you very kindly gave?
 
=DateAdd("yyyy",[Text2],[Date_Purchase]) as the control source for textbox 3, which should be unbound anyway.
 
Thanks Rich

I did it with this code

Private Sub Warranty_Period_AfterUpdate()
Dim dateX As Date
If IsNull(Me.Date_of_Purchase) = False Then
dateX = DateAdd("yyyy", Me.Warranty_Period, Me.Date_of_Purchase)
Me.Warranty_Expires = dateX
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom