Hello,
I need assistance on my function. I try to find the number of bank holiday between two dates and I wish to take into account saturdays and Sunday or only Sunday. What is strange in my function it is that I return only from the zero. I have the impression that it does not arrive at reading information in my table. Could you say to me why. Or I have make an error
Function CompteJoursFeriés(dhDébut As Date, dhFin As Date) As Integer
Dim rstNew As Recordset
Dim db As Database
Dim strFiltre As String
Dim strAncienFiltre As String
Dim intEnregistrements As Integer
Dim strSQL As String
Dim strDateFérié As Variant
On Error GoTo TraitementErreur
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblJoursFériés", dbOpenDynaset)
strDateFérié = rst("DateJourFérié")
If Not rst Is Nothing Then
If Len(strDateFérié) > 0 Then
If Left(strDateFérié, 1) <> "[" Then
strDateFérié = "[" & strDateFérié & "]"
End If
strFiltre = strDateFérié & " BETWEEN #" & dhDébut & "# AND #" & dhFin & "#"
strAncienFiltre = rst.Filter
rst.Filter = strFiltre
Set rstNew = rst.OpenRecordset()
If rstNew.RecordCount > 0 Then
rstNew.MoveLast
intEnregistrements = rstNew.RecordCount
End If
' Pour ne pas compter à double un jour férié tombant sur un weekend
rstNew.MoveFirst
Do While Not rstNew.EOF
If EstWeekend(rstNew!DateJourFérié) Then
intEnregistrements = intEnregistrements - 1
End If
rstNew.MoveNext
Loop
rstNew.Close
End If
End If
TraitementFinal:
CompteJoursFeriés = intEnregistrements
Exit Function
TraitementErreur:
Resume TraitementFinal
End Function
Function EstWeekend(dhTemp As Date) As Boolean
Select Case Weekday(dhTemp)
Case vbSaturday, vbSunday
EstWeekend = True
Case Else
EstWeekend = False
End Select
End Function
Thank you for your assistance
Nilses
I need assistance on my function. I try to find the number of bank holiday between two dates and I wish to take into account saturdays and Sunday or only Sunday. What is strange in my function it is that I return only from the zero. I have the impression that it does not arrive at reading information in my table. Could you say to me why. Or I have make an error
Function CompteJoursFeriés(dhDébut As Date, dhFin As Date) As Integer
Dim rstNew As Recordset
Dim db As Database
Dim strFiltre As String
Dim strAncienFiltre As String
Dim intEnregistrements As Integer
Dim strSQL As String
Dim strDateFérié As Variant
On Error GoTo TraitementErreur
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblJoursFériés", dbOpenDynaset)
strDateFérié = rst("DateJourFérié")
If Not rst Is Nothing Then
If Len(strDateFérié) > 0 Then
If Left(strDateFérié, 1) <> "[" Then
strDateFérié = "[" & strDateFérié & "]"
End If
strFiltre = strDateFérié & " BETWEEN #" & dhDébut & "# AND #" & dhFin & "#"
strAncienFiltre = rst.Filter
rst.Filter = strFiltre
Set rstNew = rst.OpenRecordset()
If rstNew.RecordCount > 0 Then
rstNew.MoveLast
intEnregistrements = rstNew.RecordCount
End If
' Pour ne pas compter à double un jour férié tombant sur un weekend
rstNew.MoveFirst
Do While Not rstNew.EOF
If EstWeekend(rstNew!DateJourFérié) Then
intEnregistrements = intEnregistrements - 1
End If
rstNew.MoveNext
Loop
rstNew.Close
End If
End If
TraitementFinal:
CompteJoursFeriés = intEnregistrements
Exit Function
TraitementErreur:
Resume TraitementFinal
End Function
Function EstWeekend(dhTemp As Date) As Boolean
Select Case Weekday(dhTemp)
Case vbSaturday, vbSunday
EstWeekend = True
Case Else
EstWeekend = False
End Select
End Function
Thank you for your assistance
Nilses