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 MaJ_Periodique()
Dim SQL As String, oSQL As DAO.Recordset
Dim IDPaiPer As String, LibPaiPer As String, MTPaiPer As String, MoisPaiPer As String, CodePmt As String, CodeJrnl As String, CodeSsJrnl As String, CodePaiPer As String
Dim ProchainPaiPer As Date, FuturPaiPer As Date
DoCmd.SetWarnings False
'Je lis la table PaiementPeriodique pour ne récupérer que les paiements à faire
SQL = "SELECT PaiementPeriodique.* " _
& " FROM PaiementPeriodique " _
& "WHERE PaiementPeriodique.FinPaiPer>Now() AND PaiementPeriodique.ProchainPaiPer<=Now();"
'Exécute la requête
Set oSQL = CurrentDb.OpenRecordset(SQL)
'Fait l'analyse de tous les paiements
Do Until oSQL.EOF
'Initialise mes variables
IDPaiPer = oSQL("CodePaiPer")
LibPaiPer = oSQL("LibellePaiPer")
MTPaiPer = oSQL("MontantPaiPer")
ProchainPaiPer = oSQL("ProchainPaiPer")
FuturPaiPer = DateAdd("m", 1, ProchainPaiPer) 'Ajoute un mois à la date du paiement
MoisPaiPer = Format(oSQL("ProchainPaiPer"), "MMMM") 'récupère le mois en texte
CodePmt = oSQL("CodePmt")
CodeJrnl = oSQL("CodeJrnl")
CodeSsJrnl = oSQL("CodeSsJrnl")
CodePaiPer = oSQL("CodePaiPer")
'Ajout la donnée dans la table Mouvements
MsgBox "INSERT INTO Mouvements (DateMvt, LibelleMvt, MontantMvt, CodePmt, CodeJrnl, CodeSsJrnl, CodePaiPer) " _
& "VALUES (#" & Format(ProchainPaiPer, "MM/DD/YY") & "#, """ & LibPaiPer & UCase(Left(MoisPaiPer, 1)) & LCase(Right(MoisPaiPer, Len(MoisPaiPer) - 1)) & """, " & MTPaiPer & ", " & CodePmt & ", " & CodeJrnl & ", " & CodeSsJrnl & ", " & CodePaiPer & ",)"
DoCmd.RunSQL "INSERT INTO Mouvements (DateMvt, LibelleMvt, MontantMvt, CodePmt, CodeJrnl, CodeSsJrnl, CodePaiPer) " _
& "VALUES (#" & Format(ProchainPaiPer, "MM/DD/YY") & "#, """ & LibPaiPer & UCase(Left(MoisPaiPer, 1)) & LCase(Right(MoisPaiPer, Len(MoisPaiPer) - 1)) & """, " & MTPaiPer & ", " & CodePmt & ", " & CodeJrnl & ", " & CodeSsJrnl & ", " & CodePaiPer & ",)"
'Mise à jour la date du prochain paiement dans la table PaiementPeriodique
DoCmd.RunSQL "UPDATE PaiementPeriodique SET PaiementPeriodique.ProchainPaiPer = #" & Format(FuturPaiPer, "MM/DD/YY") & "# " _
& "WHERE PaiementPeriodique.CodePaiPer=" & IDPaiPer & ";"
oSQL.MoveNext
Loop
DoCmd.SetWarnings True
End Function |
Partager