VB Code:
  1. Function ProjectedDate(dteBegDate As Date, lngNumDays As Long, blnSkipWeekEnds As Boolean, blnSkipHolidays As Boolean) As Date
  2. 'Get Forward or Backward Date from a Beginning Date
  3. 'Count starts with Day after Beginning Date
  4. 'If blnSkipWeekEnds or blnSkipHolidays = True, these days are NOT included when counting,
  5. '   hence, the projected date is <> then when they are included (= False)
  6. 'Usage
  7. '    dteNew = ProjectedDate("5/8/2004", 30, False, False)
  8.  
  9.    Dim lngCnt As Long
  10.    Dim dblBegDate As Long
  11.  
  12.    '--------------
  13.    
  14.    dblBegDate = CDbl(dteBegDate)
  15.    lngCnt = 0
  16.  
  17.    If lngNumDays > 0 Then
  18.    
  19.       Do
  20.      
  21.          'Increment Date (start with next day)
  22.          dblBegDate = dblBegDate + 1
  23.  
  24.          'Skip Weekends
  25.          If blnSkipWeekEnds Then
  26.             If WeekDay(dblBegDate) = vbSunday Then GoTo Skip
  27.             If WeekDay(dblBegDate) = vbSaturday Then GoTo Skip
  28.          End If
  29.      
  30.          'Holidays (need database/array or lookup table)
  31.          If blnSkipHolidays Then
  32.          End If
  33.          
  34.          lngCnt = lngCnt + 1
  35. Skip:
  36.      
  37.       Loop Until lngCnt = lngNumDays
  38.    
  39.    Else      'Projected Date is in the Past
  40.    
  41.       lngNumDays = Abs(lngNumDays)
  42.    
  43.       Do
  44.      
  45.          'Increment Date (start with next day)
  46.          dblBegDate = dblBegDate - 1
  47.  
  48.          'Skip Weekends in Count
  49.          If blnSkipWeekEnds Then
  50.             If WeekDay(dblBegDate) = vbSunday Then GoTo Skip1
  51.             If WeekDay(dblBegDate) = vbSaturday Then GoTo Skip1
  52.          End If
  53.      
  54.          'Holidays (need database/array or lookup table)
  55.          If blnSkipHolidays Then
  56.          End If
  57.          
  58.          lngCnt = lngCnt + 1
  59. Skip1:
  60.  
  61.       Loop Until lngCnt = lngNumDays
  62.  
  63.    End If
  64.    
  65.    ProjectDate = CDate(dblBegDate)
  66.  
  67. End Function