Question : T-1 working week Query - Ignore weekends!

Hi,

i'm trying to create a T-1 report. When I say T-1 I mean T-1 with regard to the working week i.e. Mon - fri. So if the report / query is ran on a monday it is in effect a T-3 report.

In the Criteria field of my query wizard I currently have Date() -1. Of course if this is run on a Monday this will retrieve data for Sunday instead of Friday. How can I over come this?

Thanks

Answer : T-1 working week Query - Ignore weekends!

Here's a function solving exactly this.

/gustav
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
Public Function DateSkipWeekend( _
  ByVal datDate As Date, _
  Optional ByVal booReverse As Boolean) _
  As Date
 
' Purpose: Calculate first working day equal to or following/preceding datDate.
' Assumes: 5 or 6 working days per week. Weekend is (Saturday and) Sunday.
' Limitation: Does not count for public holidays.
'
' May be freely used and distributed.
' 1999-07-03, Gustav Brock, Cactus Data ApS, CPH.
  
  Const cintWorkdaysOfWeek As Integer = 5
 
  Dim bytSunday   As Byte
  Dim bytWeekday  As Byte
  
  bytSunday = WeekDay(vbSunday, vbMonday)
  bytWeekday = WeekDay(datDate, vbMonday)
  
  If bytWeekday > cintWorkdaysOfWeek Then
    ' Weekend.
    If booReverse = False Then
      ' Get following workday.
      datDate = DateAdd("d", 1 + bytSunday - bytWeekday, datDate)
    Else
      ' Get preceding workday.
      datDate = DateAdd("d", cintWorkdaysOfWeek - bytWeekday, datDate)
    End If
  End If
 
  DateSkipWeekend = datDate
 
End Function
Open in New Window Select All
Random Solutions  
 
programming4us programming4us