Go to previous workday if weekend

  • Thread starter Joker via AccessMonster.com
  • Start date
J

Joker via AccessMonster.com

Hello Access Gurus,

I am working with Ken Getz and Mike Gilbert's date functions module. I am
using the dhPreviousWorkdayA function. I have used this function a couple of
times before with no problems. What I have is some code that calculates a
date in the future. What I need is if that date falls on a weekend just to
go back to the previous work day. Here is the code I am using for that part:

fncDueDate = Date
fncDueDate = DateSerial(Year(fncDueDate), Month([fncDueDate]), Day
(pDays) + 1)
fncDueDate = FormatDateTime(fncDueDate, vbShortDate)
DateValue (fncDueDate)
If fncDueDate = vbSaturday Or fncDueDate = vbSunday Then
DateValue (fncDueDate)
dhPreviousWorkdayA (fncDueDate)

I have tried using weekday = 1 or 7 as well.. It seems like it's ignoring the
code because it keeps landing on a Sunday.

Any help or thoughts would be greatly appreciated.
 
G

Guest

Place this function in any module:

Public Function GetWorkDay(dtDate As Date) As Date
Dim WkDay As Integer
WkDay = Weekday(dtDate)
If WkDay = 7 Then
'return friday's date
GetWorkDay = DateAdd("d", -1, dtDate)
ElseIf WkDay = 1 Then
'return friday's date
GetWorkDay = DateAdd("d", -2, dtDate)
Else
GetWorkDay = dtDate
End If
End Function

Call the function above, passing your calculated Date Due date to is with
this statement:

dim dtActualDateDue as date
dtActualDateDue = GetWorkDay(fncDueDate)

When run, if the Due Date was on a Saturday or a Sunday, the variable
"dtActualDateDue" will set to the preceeding Friday else it will be set to
the Due Date you passed to it.
 

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