PC Review


Reply
Thread Tools Rate Thread

calculate date differences and give popup box

 
 
=?Utf-8?B?V2F5bmU=?=
Guest
Posts: n/a
 
      3rd Oct 2005
Having a bit of trouble with this. What Im trying to do is calculate the
amount of working days between 2 dates, and then provide the resulting value
in a msgbox along with other text.

At the moment I have the formula working, but it is set as the "initial
value" of another field.

The formula is:

DateDiff("d", [First.Day], [Last.Day])+2 - ((DateDiff("w", [First.Day],
[Last.Day]) * 2) + 1)

This formula works perfectly when the user only inputs actual working days,
it's not accurate if they put in the date of a weekend.

Now because it's set as the initial value of another field, it automatically
calculates when either field is changed. What I want is the result of the
formula to appear in a msgbox instead of a field as a value, and anytime
either input field is updated the msgbox should come up. Is it possible?

Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2F5bmU=?=
Guest
Posts: n/a
 
      6th Oct 2005
I've now solved this but without using the msgbox, code for anyone else
looking to do the same thing:

Function calculate_Click()
leave()
End Function

Sub leave()

dStartDate = Item.UserProperties("First.Date").Value
dEndDate = Item.UserProperties("Last.Date").Value

Dim sDayDifference, tempDay, dayTally

sDayDifference = DateDiff("d", dStartDate, dEndDate) + 1
dayTally = 0
for i = 0 To (sDayDifference-1)
tempDay = FormatDateTime(dateAdd("d", i, dStartDate), 2)
If (WeekDay(tempDay) = 7) Or (Weekday(tempDay) = 1) Then
dayTally = dayTally + 1
End If
next
Item.UserProperties("LeaveDaysEntry").Value = sDayDifference - dayTally -
Item.UserProperties("PublicHolsEntry").Value

End Sub

"Wayne" wrote:

> Having a bit of trouble with this. What Im trying to do is calculate the
> amount of working days between 2 dates, and then provide the resulting value
> in a msgbox along with other text.
>
> At the moment I have the formula working, but it is set as the "initial
> value" of another field.
>
> The formula is:
>
> DateDiff("d", [First.Day], [Last.Day])+2 - ((DateDiff("w", [First.Day],
> [Last.Day]) * 2) + 1)
>
> This formula works perfectly when the user only inputs actual working days,
> it's not accurate if they put in the date of a weekend.
>
> Now because it's set as the initial value of another field, it automatically
> calculates when either field is changed. What I want is the result of the
> formula to appear in a msgbox instead of a field as a value, and anytime
> either input field is updated the msgbox should come up. Is it possible?
>
> Thanks

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does one calculate date differences in Outlook - calendar? cjones@jmwlaw Microsoft Outlook Calendar 1 2nd Apr 2008 02:32 AM
How to calculate Date & Time differences robs Microsoft Excel Discussion 8 6th Oct 2005 02:53 AM
How to calculate Date & Time differences robs Microsoft Excel Worksheet Functions 2 4th Oct 2005 04:22 PM
calculate date differences in years and months =?Utf-8?B?Sm95Y2U=?= Microsoft Excel Worksheet Functions 1 14th Mar 2005 05:18 PM
Calculate date differences Alberto Uttranadhie Microsoft Access VBA Modules 2 5th Nov 2003 08:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:09 PM.