K
kontra
Hi,
I am very very new to VB script. What I am trying to achieve is to get
Previous Business Day as Date to use in a query...
Below is the 'code' I came up with after looking on the net and this forum.
However I am still not sure what parameters to use when openning the
recordset, plus I feel that I am missing some sort of a loop function to
check for all the holidays listed in the table. Also if anyone has any
suggestions on how to correct my code I would really appreciate if you will
explain as to why, so I can understand it better and not ask the same
question again. Thank you:
**********
Option Compare Database
Option Explicit
Public Function PreviousBD() As Date
Dim dbConn As ADODB.Connection ' Not sure if needed
Dim rsHolidays ' Should be coming from tbl_Holidays in current DB
Dim bdNum
bdNum = Weekday(Date)
Set rsHolidays = CurrentDb.OpenRecordset("Select Date from tbl_Holidays")
'Not sure what parameters to use
If bdNum = 1 And Date <> rsHolidays Then
PreviousBD = Date - 3
If bdNum > 1 And Date - 1 = rsHolidays Then
PreviousBD = Date - 2
If bdNum > 1 And Date - 1 <> rsHolidays Then
PreviousBD = Date - 1
If bdNum = 2 And Date - 1 = rsHolidays Then
PreviousBD = Date - 4
If bdNum = 1 And Date - 3 = rsHolidays Then
PreviousBD = Date - 4
End If
End If
End If
End If
End If
Set rsHolidays = Nothing
End Function
*********
I am very very new to VB script. What I am trying to achieve is to get
Previous Business Day as Date to use in a query...
Below is the 'code' I came up with after looking on the net and this forum.
However I am still not sure what parameters to use when openning the
recordset, plus I feel that I am missing some sort of a loop function to
check for all the holidays listed in the table. Also if anyone has any
suggestions on how to correct my code I would really appreciate if you will
explain as to why, so I can understand it better and not ask the same
question again. Thank you:
**********
Option Compare Database
Option Explicit
Public Function PreviousBD() As Date
Dim dbConn As ADODB.Connection ' Not sure if needed
Dim rsHolidays ' Should be coming from tbl_Holidays in current DB
Dim bdNum
bdNum = Weekday(Date)
Set rsHolidays = CurrentDb.OpenRecordset("Select Date from tbl_Holidays")
'Not sure what parameters to use
If bdNum = 1 And Date <> rsHolidays Then
PreviousBD = Date - 3
If bdNum > 1 And Date - 1 = rsHolidays Then
PreviousBD = Date - 2
If bdNum > 1 And Date - 1 <> rsHolidays Then
PreviousBD = Date - 1
If bdNum = 2 And Date - 1 = rsHolidays Then
PreviousBD = Date - 4
If bdNum = 1 And Date - 3 = rsHolidays Then
PreviousBD = Date - 4
End If
End If
End If
End If
End If
Set rsHolidays = Nothing
End Function
*********