G
Guest
I would also appreciate any suggestions to make the script better (or more
correct). The Function does return the correct period (tested by changing
system date), but it's giving a data mismatch if I am trying to use it in the
query as Between #SomeDate# and #SomeDate# Thanks in advance:
******************************
Public Function CBDPeriod() ' returns current Business Days Period
Dim rsDays
Dim DayDate
Dim CDay
Dim StartDate
Dim EndDate
Dim PMonth
Set rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])=Month(Date())")
PMonth = Month(Date) - 1
DayDate = rsDays!Date
CDay = Date
If CDay = DayDate Then
Set rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])= Month(date())-1 ORDER BY Date ASC")
End If
StartDate = rsDays!Date
Debug.Print StartDate
If Month(StartDate) = PMonth Then
Set rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])= Month(date())-1 ORDER BY Date DESC")
Else:
rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])= Month(date()) ORDER BY Date DESC")
End If
EndDate = rsDays!Date
CBDPeriod = "Between " & StartDate & " and " & EndDate
Debug.Print PMonth
Debug.Print DayDate
Debug.Print CDay
Debug.Print StartDate
Debug.Print EndDate
Debug.Print CBDPeriod
End Function
***********************
correct). The Function does return the correct period (tested by changing
system date), but it's giving a data mismatch if I am trying to use it in the
query as Between #SomeDate# and #SomeDate# Thanks in advance:
******************************
Public Function CBDPeriod() ' returns current Business Days Period
Dim rsDays
Dim DayDate
Dim CDay
Dim StartDate
Dim EndDate
Dim PMonth
Set rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])=Month(Date())")
PMonth = Month(Date) - 1
DayDate = rsDays!Date
CDay = Date
If CDay = DayDate Then
Set rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])= Month(date())-1 ORDER BY Date ASC")
End If
StartDate = rsDays!Date
Debug.Print StartDate
If Month(StartDate) = PMonth Then
Set rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])= Month(date())-1 ORDER BY Date DESC")
Else:
rsDays = CurrentDb.OpenRecordset("SELECT TOP 1 Date FROM tbl_BD_2006
WHERE Month([Date])= Month(date()) ORDER BY Date DESC")
End If
EndDate = rsDays!Date
CBDPeriod = "Between " & StartDate & " and " & EndDate
Debug.Print PMonth
Debug.Print DayDate
Debug.Print CDay
Debug.Print StartDate
Debug.Print EndDate
Debug.Print CBDPeriod
End Function
***********************