Calculating Days

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I tried to use an answer to another discussion group question to come up with
this code:

Private Sub Form_Current()
Me.FirstResult = Me.ThirdDate - Me.SecondDate
Me.SecondResult = Me.ResponseDate - Me.ThirdDate
End Sub

Private Sub FourthDate_AfterUpdate()
Me.SecondResult = Me.ResponseDate - Me.ThirdDate

End Sub

Private Sub ResponseDate_AfterUpdate()
DateAdd("m", 3, #1/1/2006#) = DateAdd("m", 3, [ResponseDate])
End Sub

Private Sub ThirdDate_AfterUpdate()
Me.FirstResult = Me.ThirdDate - Me.SecondDate
End Sub


Fields:
FirstDate
SecondDate
ThirdDate
FirstResult (Number of Days Between FirstDate and SecondDate) (unbound)
ResponseDate (Calculated date =DateAdd("m",3,[ThirdDate]) (unbound)
**The due date is 3 months from ThirdDate**
FourthDate
SecondResult (Need number of days between the ResponseDate and the FourthDate)


I tried to follow the same pattern in creating the SecondResult, but I don't
think I should be putting this calculation in the CurrentForm with the
FirstResult? I guess this must have something to do with the ResponseDate
being a calculated date?

Can anybody help!?
 
When assigning a value in VBA, instead of referencing the computed control
include the original expression in the new expression:

Me.SecondResult = Me.FourthDate - DateAdd("m",3,[ThirdDate])

However, should SecondResult not simply be an unbound computed control with
a ControlSouce of:

= [FourthDate] - DateAdd("m",3,[ThirdDate])

I'm assuming FourthDate is the latter date; if not just reverse the
expression. Similarly should not FirstResult be a computed control with a
ControlSouce of:

=[SecondDate] – [FirstDate]

Again I've assumed SecondDate is the later date.

In which case you would not need any code at all.

In the above I've gone by what you say in your Fields: descriptions rather
than by your code, which does not agree with your descriptive text, and in
one case, the Response control's AfterUpdate event procedure makes no sense
as it tries to assign the return value of one DateAdd function call to
another DateAdd function call. That can't be done. As it happens that event
would never actually fire as a control's AfterUpdate event only fires when
the user updates the control, not when a value is assigned to it in code.

Ken Sheridan
Stafford, England
 
Back
Top