A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Calculating Days



 
 
Thread Tools Display Modes
  #1  
Old August 26th, 2006, 09:03 PM posted to microsoft.public.access.forms
Sharon
external usenet poster
 
Posts: 491
Default Calculating Days

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!?



--
S
  #2  
Old August 27th, 2006, 01:13 AM posted to microsoft.public.access.forms
Ken Sheridan
external usenet poster
 
Posts: 3,433
Default Calculating Days

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

"Sharon" wrote:

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!?



--
S


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.