Multiple Dates

M

mikeinohio

I have a form that has 7 date fields on it. 6 of those fields must contain a
specific date based on what the date the first one has for example:

date1 = todays date or any date

date2 = 55 days later. date3 = 59 days later, date4 = 115 days later, date5
= 119 days later, date6 = 175 days, and date7 = 179 days later.

The AddDate function works perfect to do it but the actual date displayed
must be displayed in a way to modified individually in case something was not
dont on the specific date but you can actually change it in the text box.
 
A

Al Campagna

mikeinohio,
If I understand correctly...
Use the AfterUpdate event of Date1...
Date2 = DateAdd("d",55,Date1)
Date3 = DateAdd("d",59,Date1)
etc... for each date2-7 field.
Those date fields will all be editable.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
N

NKTower

Let's say your date-holding text boxes are named
txt_Date_1, ..., txt_Date_7

and are presumably bound to table columns Date_1, ..., Date_7 of type
DateTime.

In your form, try this:

Private Sub txt_Date_1_AfterUpdate()
If IsNull(Me.txt_Date_2) Then _
Me.txt_Date_2 = DateAdd("d", 55, Me.txt_Date_1)
If IsNull(Me.txt_Date_3) Then _
Me.txt_Date_3 = DateAdd("d", 59, Me.txt_Date_1)
If IsNull(Me.txt_Date_4) Then _
Me.txt_Date_4 = DateAdd("d", 55, Me.txt_Date_1)
If IsNull(Me.txt_Date_5) Then _
Me.txt_Date_5 = DateAdd("d", 115, Me.txt_Date_1)
If IsNull(Me.txt_Date_6) Then _
Me.txt_Date_6 = DateAdd("d", 119, Me.txt_Date_1)
If IsNull(Me.txt_Date_7) Then _
Me.txt_Date_7 = DateAdd("d", 179, Me.txt_Date_1)
End Sub

( The <space><underline> is used to "wrap" a long line, I did this
so it would fit in the forum window.

What this does it put a value into the 2nd thru 7th date, but it is still an
editable item, so it can be over-ridden.

You dind't say if changing, say, the 3rd date shoudl cause a ripple effect
upon subsequent dates. if so, you could handle that as well. Such as, say

Private Sub txt_Date_3_AfterUpdate()
Dim int_Bump As Integer
int_Bump = 21 ' how many days beyond date_3

' Only do this if there is already a value in the next date field
If Not IsNull(Me.txt_Date_4) Then _
Me.txt_Date_4 = DateAdd("d",int_Bump,Me.txt_Date_3)
End If
End Sub

Note that if you have this for each, it will ripple through
 
M

mikeinohio

This is what i have in the afterupdate:

Private Sub date1_AfterUpdate(Cancel As Integer)
If IsNull(Me.date2) Then
Me.date2 = DateAdd("d", 55, Me.date1)
If IsNull(Me.date3) Then
Me.date3 = DateAdd("d", 59, Me.date1)
If IsNull(Me.date4) Then
Me.date4 = DateAdd("d", 55, Me.date1)
If IsNull(Me.date5) Then
Me.date5 = DateAdd("d", 115, Me.date1)
If IsNull(Me.date6) Then
Me.date6 = DateAdd("d", 119, Me.date1)
If IsNull(Me.date7) Then
Me.date7 = DateAdd("d", 179, Me.date1)
End Sub
It still did not work
 
M

mikeinohio

i tried it this way:

Private Sub date1_AfterUpdate(Cancel As Integer)
date2 = DateAdd("d", 55, date1)
date3 = DateAdd("d", 59, date1)
date4 = DateAdd("d", 115, date1)
date5 = DateAdd("d", 119, date1)
date6 = DateAdd("d", 175, date1)
date7 = DateAdd("d", 179, date1)
End Sub

it didnt work, the error message i get is "The expression Afterupdate as the
event proerty setting produced the following error: Procedure does not match
description of event or procedure having the same name."
 
N

NKTower

You missed a subtle thing. Those IF xxxx THEN xxxx
lines in my code are logical one-liners, but wrapped via the continuation
sequemce <blank><underline> so that they wouldn't work-wrap in the forum
window.

If statements come in several forms:


if condition then singlestatement

if condition then
one_or_more_statements
end if

if condition then
one-or-more-statements
else
one-or-more-statements
end if

My example used the first format, but the line had to be wrapped to fit the
forum display.


You can fix it either by putting the <blank><underline> after each of the
THENs in my code, OR by putting an END IF on a separate line after the
replacement statement.

Variation 1 - unwrap the line

if IsNull(me.txt_date_2) then me.txt_date_2 = DateAdd("d",55,me.txt_date_1)

(with my luck the above line will wrap. It REALLY is one line

Variation 2 - put in the underline

if IsNull(Me.txt_Date_2) Then _ <---- see the space underline?
Me.txt_Date_2 = DateAdd("d",55,Me.txt_Date_1)

Variation 3 -
if IsNull(Me.txt_Dat_2) Then
Me.txt_Date_2 = DateAdd("d",55,Me.txt_Date_1)
End If
 
M

mikeinohio

it worked perfect, and thank you..... but i noticed that if you made a
mistate with the starting date, it wont recalculate the date but only if you
go to a new record, is there a solution to this?
 
N

NKTower

My original intent was to only ripple down into subsequent dates if there was
no value there - that's what the IsNull testing is for. You have many
options. Here are two

a) a "Clear All" button - it sets all of the dates to NULL. Your user can
then try again.

Private Sub btn_ClearAll_Click()
Me.txt_Date_1.Value = Null
...
Me.txt_Date_7.Value = Null
End Sub

b) remove the
If IsNull(something) Then
and just slam the dates in whether there is a date there already or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top