Increment date by six

Angel69

Registered User.
Local time
Today, 17:56
Joined
Jun 11, 2013
Messages
86
I have the following code that updates the end date to be the same as the start date after the user tabs out of the start date. Instead of making it the same date, I want it to be six days later. How do I add that?

For example, user enters 11/10/13 in the start date. I want the end date to automatically update to 11/16/2013.

TIA!!

Code:
Private Sub StartDate_AfterUpdate()
 
Dim datDate As Date
 
If Nz(Me!StartDate.Value, #1/1/1900#) = #1/1/1900# Then
    'The user removed the START data as criterion, so remove the END date.
    Me!EndDate.Value = Null
    GoTo Exit_Now
End If
 
datDate = Nz(Me!StartDate.Value, #1/1/1900#)
If IsDate(datDate) = True Then
    Me!EndDate.Value = datDate
Else
    MsgBox "Your start date is not a valid date.  Try again."
    Me!StartDate.SetFocus
End If
 
Exit_Now:
Exit Sub
 
End Sub
 
The function you are looking for is DateAdd()

This will allow you to specify how you want to increment the value (days, hours, etc.), and how much you want to increment it.

So for what you are looking for the code would be:

Code:
Me.EndDate = DateAdd("d", 6, Me.StartDate)
 

Users who are viewing this thread

Back
Top Bottom