PC Review


Reply
Thread Tools Rate Thread

Calculating a Date but Adjusting the End Date if on a Weekend

 
 
=?Utf-8?B?YnJmZW5kZXI=?=
Guest
Posts: n/a
 
      14th Apr 2006
I am trying to calculate the end date (EndDate) in a report based on a case.
The start date (StartDate) is in another field on the report. I know (to the
best of my ability) how to add the number of days to the StartDate using the
"Select Case" function. However, if the EndDate is on a Saturday or Sunday,
I need to move it to the next weekday (add 2 or 1 more days).

I've tried picking pieces from different posts in the forum, but I still get
EndDate on a Saturday or Sunday. I am somewhere around Beginner and Novice
when it comes to code. Here's what I have so far:

Select Case Me.Customer

Case "Cust1"
If (Weekday((Me.EndDate = DateAdd("d", 58, Me.StartDate)), vbSunday)
= vbSaturday) Then
Me. EndDate = DateAdd("d", 60, Me.StartDate)

ElseIf (Weekday((Me. EndDate = DateAdd("d", 58, Me.StartDate)),
vbSunday) = vbSunday) Then
Me.EndDate = DateAdd("d", 59, Me.StartDate)

Else: Me.EndDate = DateAdd("d", 58, Me.StartDate)

End If

Case "Cust2"
If (Weekday((Me.EndDate = DateAdd("d", 57, Me.StartDate)), vbSunday)
= vbSaturday) Then
Me.EndDate = DateAdd("d", 59, Me.StartDate)

ElseIf (Weekday((Me.EndDate = DateAdd("d", 57, Me.StartDate)),
vbSunday) = vbSunday) Then
Me.EndDate = DateAdd("d", 58, Me.StartDate)

Else: Me.EndDate = DateAdd("d", 57, Me.StartDate)

End If

Case Else
If (Weekday((Me.EndDate = DateAdd("d", 65, Me.StartDate)), vbSunday)
= vbSaturday) Then
Me.EndDate = DateAdd("d", 67, Me.StartDate)

ElseIf (Weekday((Me.EndDate = DateAdd("d", 65, Me.StartDate)),
vbSunday) = vbSunday) Then
Me.EndDate = DateAdd("d", 66, Me.StartDate)

Else: Me.EndDate = DateAdd("d", 65, Me.StartDate)

End If

End Select

Thank you in advance.
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      14th Apr 2006
Take a look in the Date/Time section of "The Access Web"
(http://www.mvps.org/access/) for a couple of options, or look at my
September, 2004 "Access Answers" column in Pinnacle Publiation's "Smart
Access". You can download the column (and sample database) for free at
http://www.accessmvp.com/djsteele/SmartAccess.html

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"brfender" <(E-Mail Removed)> wrote in message
news:46C018B6-7E38-49E6-91B8-(E-Mail Removed)...
>I am trying to calculate the end date (EndDate) in a report based on a
>case.
> The start date (StartDate) is in another field on the report. I know (to
> the
> best of my ability) how to add the number of days to the StartDate using
> the
> "Select Case" function. However, if the EndDate is on a Saturday or
> Sunday,
> I need to move it to the next weekday (add 2 or 1 more days).
>
> I've tried picking pieces from different posts in the forum, but I still
> get
> EndDate on a Saturday or Sunday. I am somewhere around Beginner and
> Novice
> when it comes to code. Here's what I have so far:
>
> Select Case Me.Customer
>
> Case "Cust1"
> If (Weekday((Me.EndDate = DateAdd("d", 58, Me.StartDate)),
> vbSunday)
> = vbSaturday) Then
> Me. EndDate = DateAdd("d", 60, Me.StartDate)
>
> ElseIf (Weekday((Me. EndDate = DateAdd("d", 58, Me.StartDate)),
> vbSunday) = vbSunday) Then
> Me.EndDate = DateAdd("d", 59, Me.StartDate)
>
> Else: Me.EndDate = DateAdd("d", 58, Me.StartDate)
>
> End If
>
> Case "Cust2"
> If (Weekday((Me.EndDate = DateAdd("d", 57, Me.StartDate)),
> vbSunday)
> = vbSaturday) Then
> Me.EndDate = DateAdd("d", 59, Me.StartDate)
>
> ElseIf (Weekday((Me.EndDate = DateAdd("d", 57, Me.StartDate)),
> vbSunday) = vbSunday) Then
> Me.EndDate = DateAdd("d", 58, Me.StartDate)
>
> Else: Me.EndDate = DateAdd("d", 57, Me.StartDate)
>
> End If
>
> Case Else
> If (Weekday((Me.EndDate = DateAdd("d", 65, Me.StartDate)),
> vbSunday)
> = vbSaturday) Then
> Me.EndDate = DateAdd("d", 67, Me.StartDate)
>
> ElseIf (Weekday((Me.EndDate = DateAdd("d", 65, Me.StartDate)),
> vbSunday) = vbSunday) Then
> Me.EndDate = DateAdd("d", 66, Me.StartDate)
>
> Else: Me.EndDate = DateAdd("d", 65, Me.StartDate)
>
> End If
>
> End Select
>
> Thank you in advance.



 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      14th Apr 2006
brfender wrote:

>I am trying to calculate the end date (EndDate) in a report based on a case.
>The start date (StartDate) is in another field on the report. I know (to the
>best of my ability) how to add the number of days to the StartDate using the
>"Select Case" function. However, if the EndDate is on a Saturday or Sunday,
>I need to move it to the next weekday (add 2 or 1 more days).
>
>I've tried picking pieces from different posts in the forum, but I still get
>EndDate on a Saturday or Sunday. I am somewhere around Beginner and Novice
>when it comes to code. Here's what I have so far:
>
>Select Case Me.Customer
>
> Case "Cust1"
> If (Weekday((Me.EndDate = DateAdd("d", 58, Me.StartDate)), vbSunday)
>= vbSaturday) Then
> Me. EndDate = DateAdd("d", 60, Me.StartDate)
>
> ElseIf (Weekday((Me. EndDate = DateAdd("d", 58, Me.StartDate)),
>vbSunday) = vbSunday) Then
> Me.EndDate = DateAdd("d", 59, Me.StartDate)
>
> Else: Me.EndDate = DateAdd("d", 58, Me.StartDate)
>
> End If

[snip similar cases]


It's not quite that complicated:

Case "Cust1"
tmpEnd = DateAdd("d", 58, Me.StartDate))
tmpDay = Weekday(tmpEnd , vbMonday)
If tmpDay > 5 Then
Me. EndDate = DateAdd("d", 8 - tmpDay, tmpEnd)
End If
Case "Cust2"
. . .

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
=?Utf-8?B?YnJmZW5kZXI=?=
Guest
Posts: n/a
 
      17th Apr 2006
Thanks Marsh. This was a lot simpler than the way I was trying. Easier to
understand, too.

"Marshall Barton" wrote:

> brfender wrote:
>
> >I am trying to calculate the end date (EndDate) in a report based on a case.
> >The start date (StartDate) is in another field on the report. I know (to the
> >best of my ability) how to add the number of days to the StartDate using the
> >"Select Case" function. However, if the EndDate is on a Saturday or Sunday,
> >I need to move it to the next weekday (add 2 or 1 more days).
> >
> >I've tried picking pieces from different posts in the forum, but I still get
> >EndDate on a Saturday or Sunday. I am somewhere around Beginner and Novice
> >when it comes to code. Here's what I have so far:
> >
> >Select Case Me.Customer
> >
> > Case "Cust1"
> > If (Weekday((Me.EndDate = DateAdd("d", 58, Me.StartDate)), vbSunday)
> >= vbSaturday) Then
> > Me. EndDate = DateAdd("d", 60, Me.StartDate)
> >
> > ElseIf (Weekday((Me. EndDate = DateAdd("d", 58, Me.StartDate)),
> >vbSunday) = vbSunday) Then
> > Me.EndDate = DateAdd("d", 59, Me.StartDate)
> >
> > Else: Me.EndDate = DateAdd("d", 58, Me.StartDate)
> >
> > End If

> [snip similar cases]
>
>
> It's not quite that complicated:
>
> Case "Cust1"
> tmpEnd = DateAdd("d", 58, Me.StartDate))
> tmpDay = Weekday(tmpEnd , vbMonday)
> If tmpDay > 5 Then
> Me. EndDate = DateAdd("d", 8 - tmpDay, tmpEnd)
> End If
> Case "Cust2"
> . . .
>
> --
> Marsh
> MVP [MS Access]
>

 
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
formual to determine if date falls on weekend, adjust date to Mond Bradley Microsoft Excel Misc 4 21st Nov 2008 06:19 PM
EXCLUDE WEEKEND DATES*** SHIP DATE - TOTAL DAYS = START DATE =?Utf-8?B?S3Jpc3RhbHRpcHM=?= Microsoft Access 4 22nd Mar 2007 01:58 PM
Calculating a Due Date that is not a holiday or weekend Smythe32@aol.com Microsoft Excel Programming 3 14th Dec 2006 02:22 AM
Calculating a past date in Access that excludes weekend =?Utf-8?B?RA==?= Microsoft Access Form Coding 1 26th Apr 2006 06:09 PM
Coding to show first _weekday_ prior to a date, when date calculation happens to fall on weekend? StargateFan Microsoft Excel Programming 5 9th Dec 2004 09:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:47 AM.