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 44 45 46 47 48 49 50 51 52 53 54 55
| Option Explicit
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
Dim CodeJrnl As String, CodeSsJrnl As String, RefAnal As String, CodePaiPer As String, Paiement As String, RefCompte 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 T_PaiementPeriodique.* " _
& " FROM T_PaiementPeriodique " _
& "WHERE T_PaiementPeriodique.FinPaiPer>= #" & Format(Now(), "mm/dd/yy") & _
"# AND T_PaiementPeriodique.ProchainPaiPer<= #" & Format(Now(), "mm/dd/yy") & "#"
'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
Paiement = oSQL("Paiement")
CodeJrnl = oSQL("CodeJrnl")
CodeSsJrnl = oSQL("CodeSsJrnl")
CodePaiPer = oSQL("CodePaiPer")
RefAnal = Nz(oSQL("RefAnal"), "")
RefCompte = oSQL("RefCompte")
'Ajout la donnée dans la table Mouvements
DoCmd.RunSQL "INSERT INTO T_Mouvements (RefCompte,DateMvt, LibelleMvt, MontantMvt, Paiement, CodeJrnl, CodeSsJrnl, RefAnal, CodePaiPer) " _
& "VALUES ( """ & RefCompte & """, #" & Format(ProchainPaiPer, "MM/DD/YY") & "#, """ & LibPaiPer & " " & UCase(Left(MoisPaiPer, 1)) & LCase(Right(MoisPaiPer, Len(MoisPaiPer) - 1)) & """, " & Replace(MTPaiPer, ",", ".") & ", """ & Paiement & """, """ & CodeJrnl & """, """ & CodeSsJrnl & """, """ & RefAnal & """, """ & CodePaiPer & """)"
If IsNull(rs.Fields("RefAnal").Value) Then
RefAnal = ""
Else
RefAnal = oSQL("RefAnal")
End If
'Mise à jour la date du prochain paiement dans la table PaiementPeriodique
DoCmd.RunSQL "UPDATE T_PaiementPeriodique SET T_PaiementPeriodique.ProchainPaiPer = #" & Format(FuturPaiPer, "MM/DD/YY") & "# " _
& "WHERE T_PaiementPeriodique.CodePaiPer=" & IDPaiPer & ";"
oSQL.MoveNext
Loop
DoCmd.SetWarnings True
End Function |
Partager