1.

Solve : Date Calculations in Access?

Answer»

How do I adapt the FOLLOWING so that the "new date" ignores Saturday and/ or Sunday? For example: the user SELECTS April 7 from a calendar control. He/she wants the new date to be 5 business days from the date selected. The new date should be April 14 because 5 business days from April 7 should not consider Saturday and Sunday as business days.

Dim FirstDate As Date
Dim IntervalType As String
Dim Number As Integer
Dim Msg
IntervalType = "d" '"d" specifies days as interval
FirstDate = Calendar1
Number = InputBox("Enter number of days to add")
Msg = "New date: " & DateAdd(IntervalType, Number, FirstDate)


I'm also trying to figure out how this would apply to ignoring holidays (I have a holiday table).First I would setup a WeendEnd Function:

Code: [Select]Function IsWeekend(dt)
Select Case Weekday(dt)
Case vbSaturday, vbSunday
IsWeekend = True
Case Else
IsWeekend = False
END Select
End Function

Your code is then something like this:

Code: [Select]busday = 'use the value from the date picker control
tot = 0

Do until tot = 5
busday = dateadd("d", 1, busday)
if IsWeekend(busday) = False
tot = tot + 1
end if
Next
Msg = "New date: " & busday

The theory is the same with holidays. Just check if the new busday is a holiday and ignore the tot counter.



Discussion

No Comment Found