1 2 3 4 5 6 7 8
| For Q = 1 To Mois_cloture
.MoveNext
DoCmd.SetWarnings False
Valeur_Prod = -((Nz(DSum("[MONTANTLOCAL]", "sous_requete_productions", "[idpays]=" & MonRst.Fields("idpays") & " and [id_groupe_affaire]=" & MonRst.Fields("id_groupe_affaire") & " and [idmois]<=" & Q & "") / 1000 / DLookup("taux", "sous_requete_productions", "[idsite] =" & MonRst.Fields("idSite") & " and [idmois]=" & Q & ""), 0) - Nz(DSum("[MONTANTLOCAL]", "sous_requete_productions", "[idpays]=" & MonRst.Fields("idpays") & " and [id_groupe_affaire]=" & MonRst.Fields("id_groupe_affaire") & " and [idmois]<" & Q & "") / 1000 / DLookup("taux", "sous_requete_productions", "[idsite] =" & MonRst.Fields("idSite") & " and [idmois]=" & Q & ""), 0)))
StrSQL = "insert INTO TEST select distinct idpays,pays,site,id_groupe_affaire,groupe_affaire,libellegroupeaffaire,idmois, (-((Nz(DSum(""[MONTANTLOCAL]"", ""sous_requete_productions"", ""[idpays]=" & MonRst.Fields("idpays") & " and [idsite]=" & MonRst.Fields("idsite") & " and [id_groupe_affaire]=" & MonRst.Fields("id_groupe_affaire") & " and [idmois]<=" & Q & """) / 1000 / DLookup(""taux"", ""sous_requete_productions"", ""[idsite] =" & MonRst.Fields("idSite") & " and [idmois]=" & Q & """), 0) - Nz(DSum(""[MONTANTLOCAL]"", ""sous_requete_productions"", ""[idpays]=" & MonRst.Fields("idpays") & " and [idsite]=" & MonRst.Fields("idsite") & " and [id_groupe_affaire]=" & MonRst.Fields("id_groupe_affaire") & " and [idmois]<" & Q & """) / 1000 / DLookup(""taux"", ""sous_requete_productions"", ""[idsite] =" & MonRst.Fields("idSite") & " and [idmois]=" & Q & """), 0)))) as Valeur from sous_requete_productions where idmois=" & Q & ""
DoCmd.RunSQL StrSQL
'DoCmd.RunSQL "update test set [valeur]='" & Format(Valeur_Prod, "fixed") & "'"
Next Q |
Partager