1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Private Function CalculerTotalCerf() As Long
Dim DateRef As Date
Dim DateControle As Date
Dim DateDebutSaison As Date
Dim DateFinSaison As Date
Dim DateDebutSaisonPrecedente As Date
Dim DateFinSaisonPrecedente As Date
Dim DateRef2 As Date
Dim DateJour As Date
Dim TotalGibier As Long
Dim TotalCerf2 As Long
DateJour = Now
DateRef = DateSerial(Year(Now), Month(12), 1) 'determiner la date 1 janvier
DateControle = Format(DateSerial(Year(DateRef), Month(DateRef) + 5, -1)) 'Determiner la date du Bascule d'une année sur l'autre (1 juin de chaque année)
' Determiner les dates de debut et fin saison précedente
DateDebutSaisonPrecedente = Format(DateSerial(Year(DateRef), Month(DateRef) - 7, 1)) '1 juin année précedente
DateFinSaisonPrecedente = Format(DateSerial(Year(DateRef), Month(DateRef) + 5, -1)) '30mai de l'année en cour
' Determiner les dates de debut et fin saison en cours
DateDebutSaison = Format(DateSerial(Year(DateRef), Month(DateRef) + 5, 1)) 'Determiner la date du 1 juin de l'année en cour
DateFinSaison = Format(DateSerial(Year(DateRef), Month(DateRef) + 17, -1)) 'determiner la date du 30 mai de l'année suivante
If DateJour <= DateControle Then
TotalCerf = DSum("[Quantité]", "TbeGibierSortant", "[Gibier]='Cerf(s)' AND [DateSaisie]>=#" & Format(DateDebutSaisonPrecedente, "dd-mm-yyyy") & "# AND [DateSaisie]<= #" & Format(DateFinSaisonPrecedente, "dd-mm-yyyy") & "#") 'Utiliser yyyy-mm-dd évite les ambiguité sur la date
End If
If IsNull(TotalCerf) Or (TotalCerf) = "" Then
CalculerTotalCerf = = "0" ' pour éviter le message d'erreur dans mon champ
Else
CalculerTotalCerf = TotalCerf
End If
End Function |
Partager