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 36 37 38 39 40 41 42 43
| Function ProchainNumeroPiece(intAnnee As Integer, intMois As Integer)
Dim strFiltre As String
Dim test As Variant
Dim Vartest As Variant
Dim varAncienNumero As Variant
'---------------------------------------------------------
' Récupération du dernier n° utilisé pour le mois en cours
'---------------------------------------------------------
Vartest = Nz(DMax("Val(Right([calculdate],4))", "Factures"), "Val(Right([calculdate],4))='" & Format(intAnnee, "0000") & Format(intMois, "00") & "'")
'---------------------------------------------------------
' Construction du filtre en fonction des paramètres reçus
'---------------------------------------------------------
strFiltre = "Left([calculdate], 6) ='" & Format(intAnnee, "0000") & Format(intMois, "00") & "'"
test = Nz(DMax("Val(Right([calculdate], 4))", "temp", strFiltre), 0)
If test = 0 Then
varAncienNumero = Val(Left(Vartest, 1))
Else
varAncienNumero = test
End If
ProchainNumeroPiece = Nz(varAncienNumero, 0) + 1
End Function
' -------------------------------------------------------
' Formater la piece
' -------------------------------------------------------
Function FormaterPiece(intAnnee As Integer, intMois As Integer, intNumero As Integer)
FormaterPiece = Format(intAnnee, "0000") & Format(intMois, "00") & Format(intNumero, "0000")
End Function
' -------------------------------------------------------
' Calcul du n°de piece avec le formatage
' -------------------------------------------------------
Function ProchainNumeroFormate(intAnnee As Integer, intMois As Integer)
Dim intNumero As Integer
intNumero = ProchainNumeroPiece(intAnnee, intMois)
ProchainNumeroFormate = FormaterPiece(intAnnee, intMois, intNumero)
End Function |
Partager