ST4RCUTTER
Registered User.
- Local time
- Today, 00:51
- Joined
- Aug 31, 2006
- Messages
- 94
This problem has been brought up before and solved in a number of ways. I have been working on a module to do this...but in my own unique way. Here is the grist of it. I am trying to setup several textboxes with "target dates" that will give me the next business date (Mon - Fri). The textboxes will be setup with the function =NextBizDay(x) where "x" is the number of days to skip. For example, there are two target dates:
To make matters interesting, there can be an Original FOC date or multiple supplementary FOC dates if the project slips. In the latter case I had to find the last Supplementary FOC date. These dates are stored in two different tables.
----------------------------------------------------------
My NextBizDay function will first determine the last Supplemental FOC date if it exists and assign it to variable "MyDate". If it doesn't exist then MyDate assumes the value of the project's "Original FOC Date". (This works!)
(2) The function then tests to see if MyDate is on a Saturday or Sunday or if it falls on a holiday found in tbl_Holidays. If it falls on (Sun, Mon, Tues, Wed, Thrs, or a holiday it adds 1 day. If MyDate is on a Friday it adds 3 days. If MyDate is on a Saturday it adds 2 days. My function is giving me the error, "Compile Error: Statements and labels invalid between Select Case and first Case "
Here is the code:
Send Design Docs Date = FOC date + 5days Example: NextBizDay(5)
Receive Design Docs Date =FOC date + 10days Example: NextBizDay(10)
To make matters interesting, there can be an Original FOC date or multiple supplementary FOC dates if the project slips. In the latter case I had to find the last Supplementary FOC date. These dates are stored in two different tables.
----------------------------------------------------------
My NextBizDay function will first determine the last Supplemental FOC date if it exists and assign it to variable "MyDate". If it doesn't exist then MyDate assumes the value of the project's "Original FOC Date". (This works!)
(2) The function then tests to see if MyDate is on a Saturday or Sunday or if it falls on a holiday found in tbl_Holidays. If it falls on (Sun, Mon, Tues, Wed, Thrs, or a holiday it adds 1 day. If MyDate is on a Friday it adds 3 days. If MyDate is on a Saturday it adds 2 days. My function is giving me the error, "Compile Error: Statements and labels invalid between Select Case and first Case "
Here is the code:
Code:
Option Compare Database
Function NextBizDay(intAddDays As Integer)
Dim FDate As Date
Dim MSDate As Date
'Determine value of Start Date (Firm Order Commitment Date or Supplemental FOC Date)
FDate = Nz(DLookup("[qry_form_lastFOC]![LastDate]", "qry_form_lastFOC", "[qry_form_lastFOC]![LastFOC] > 0")) 'Checks for possible existence of Sup FOC
ODate = DLookup("[DateEntered]", "qry_date_targets", "[qry_date_targets]![DateRefID]= 38") 'Finds value of Original FOC in table which always exists
If FDate = 0 Then MyDate = ODate Else MyDate = FDate 'Sets Sup FOC as MyDate if available
For i = i To intAddDays 'Loops for the number of days requested.
Wkd = Weekday(MyDate)
Select Case Wkd = 1 'Check for Sunday
MyDate = DateAdd("d", 1, MyDate)
Holidays (MyDate)
Case Wkd = 2
MyDate = DateAdd("d", 1, MyDate)
Holidays (MyDate)
Case Wkd = 3
MyDate = DateAdd("d", 1, MyDate)
Holidays (MyDate)
Case Wkd = 4
MyDate = DateAdd("d", 1, MyDate)
Holidays (MyDate)
Case Wkd = 5
MyDate = DateAdd("d", 1, MyDate)
Holidays (MyDate)
Case Wkd = 6
MyDate = DateAdd("d", 3, MyDate)
Holidays (MyDate)
Case Wkd = 7
MyDate = DateAdd("d", 2, MyDate)
Holidays (MyDate)
End Select
Next i
MsgBox MyDate
End Function
Public Function Holidays(chkDate As Date)
'This will check the value of MyDate against the table of company holidays and add a day if any matches are found.
If chkDate = DLookup("[tbl_Holidays]![HolidayDate]", "tbl_Holidays", "[tbl_Holidays]![HolidayDate] = chkDate") Then MyDate = DateAdd("d", 1, MyDate) Else MyDate = MyDate
End Function