Forcer un calcul automatique

ddove53 Messages postés 623 Date d'inscription mardi 20 mars 2007 Statut Membre Dernière intervention 15 juin 2010 - 13 mai 2008 à 17:00
ddove53 Messages postés 623 Date d'inscription mardi 20 mars 2007 Statut Membre Dernière intervention 15 juin 2010 - 14 mai 2008 à 09:07
Bonjour, j'ai une fonction qui calcule automatiquement la répartition d'un budget sur les années.Le calcul automatique marche bien mais je veux pouvoir forcer la répartition du budget directement en écrivant dans le vaSpread.
En un mot je veux que quand j'écris dans le vaSpread il tient en compte ce que j'écris et non le calcul automatique.
Merci d'avance.Voici la fonction:

Sub Eclate_budget()
Dim Db As Database
Dim Rs As Recordset
Dim rsbud As Recordset
Dim n As Integer
Dim annéeDep As Integer
Dim année As Integer
Dim AnnéeCour As Integer
Dim SQL As String
Dim sqlbud As String
Dim total As Double
Dim totalBud As Double
Dim DelaiPaiement As Integer

Set Db = DBEngine.OpenDatabase(glob_DB_Aff(1).chemin)
Set Rs = Db.OpenRecordset("affaire")
annéeDep = Year(Rs![date deb cal])
'Rs.Close
'Set Rs Db.OpenRecordset("select [date situation],[delaipaiement] from sousreseau where [code reseau] " & glob_sres)

If Not IsNull(Rs![date situation]) Then AnnéeCour = Year(Rs![date situation]) Else AnnéeCour = annéeDep
If IsNull(Rs![Delai Paiement]) Then DelaiPaiement = 0 Else DelaiPaiement = nz(Rs![Delai Paiement])
Rs.Close

'mise à jour des niveaux 1 avec les niveaux 2 par opération dans Ressources_OP
If nivFinancier = True Then
    Dim Bdd As String
    Bdd = glob_DB_Aff(typaffaire).chemin
    Set Db = DBEngine.OpenDatabase(Bdd)
    On Error Resume Next
    Db.Execute "DROP TABLE [tempo ress_op1]"
    On Error GoTo 0
    '1-création table temporaire tempo ress_op1
    Db.Execute "SELECT Ressources_OP.[Code Sres], Left([Code OT],1) AS n1, Sum(Ressources_OP.Budget) AS Bu, Sum(Ressources_OP.[Consommé anterieur]) AS ca, Sum(Ressources_OP.Consommé) AS Co, Sum(Ressources_OP.Reste) AS r, Sum(Ressources_OP.CFP) AS cf INTO [tempo ress_op1] From Ressources_OP Where (((Len([Code OT])) = 2) And ((Ressources_OP.[Code Sres]) = " & glob_sres & ")) GROUP BY Ressources_OP.[Code Sres], Left([Code OT],1);"
    '2-mise à jour dans table Ressources_OP avec la table tempo ress_op1
    Db.Execute "UPDATE Ressources_OP INNER JOIN [tempo ress_op1] ON (Ressources_OP.[Code OT] = [tempo ress_op1].n1) AND (Ressources_OP.[Code Sres] = [tempo ress_op1].[Code Sres]) SET Ressources_OP.Budget = [Bu], Ressources_OP.[Consommé anterieur] = [ca], Ressources_OP.Consommé = [Co], Ressources_OP.Reste = [r], Ressources_OP.CFP = [cf];"
End If

'année = annéeDep
sqlbud "select * from budget where projet " & glob_sres
Set rsbud = Db.OpenRecordset(sqlbud, dbOpenDynaset)
If IsNull(dgsr1.Text7.text) Or dgsr1.Text7.text "" Then dgsr1.Text7.text 0        'CPF

Do Until rsbud.EOF

    For année = annéeDep To AnnéeCour - 1
        total = total + rsbud.Fields("N" & année - annéeDep + 1)
    Next année

    For année = AnnéeCour To annéeDep + 19       'la table budget n'a que 20 champ pour 20 année de calcul

        SQL = "SELECT Budget.Projet, Budget.Macrotache, OET.do, OET.fo,DateAdd('d','" & DelaiPaiement & "',[do]) AS Ddo, DateAdd('d','" & DelaiPaiement & "',[fo]) AS Dfo, Ressources_OP.Budget, ressources_op.cfp, "
      
        If AnnéeCour = année Then 'trouver le nombre de jours pour la repartition du budget
            SQL = SQL & " IIf([Ddo]>#31/12/" & AnnéeCour - 1 & "#,DateDiff('d',[Ddo],[Dfo]),DateDiff('d',#31/12/" & AnnéeCour - 1 & "#,[Dfo])) as nbjour, "
   
        Else
            SQL = SQL & " iif(Not IsNull([reste]), "
            SQL = SQL & " IIf([Ddo]>#31/12/" & AnnéeCour & "#,DateDiff('d',[Ddo],[Dfo]),DateDiff('d',#31/12/" & AnnéeCour & "#,[Dfo])), "
            SQL = SQL & " IIf([Ddo]>#31/12/" & AnnéeCour - 1 & "#,DateDiff('d',[Ddo],[Dfo]),DateDiff('d',#31/12/" & AnnéeCour - 1 & "#,[Dfo])) "
            SQL = SQL & ") as nbjour, "
        End If
       
        If dgsr1.Text7.text = 0 Then 'choix entre le budget ou le cpf pour le calcul de la repartition
            If année = AnnéeCour Then
                SQL = SQL & "([budget]-[consommé anterieur] - " & Int(total) & ")/[nbjour] AS [cout jour], "
            Else
                SQL = SQL & "iif(Not IsNull([reste]),([budget]-[consommé anterieur] - [consommé] - [reste] - " & Int(total) & ")/[nbjour],"
                SQL = SQL & "([budget]-[consommé anterieur] - " & Int(total) & ")/[nbjour] )"
                SQL = SQL & " AS [cout jour], "
            End If
        Else
            If année = AnnéeCour Then
                SQL = SQL & "([cfp]-[consommé anterieur] - " & Int(total) & ")/[nbjour] AS [cout jour], "
            Else
                SQL = SQL & "iif(Not IsNull([reste]),([cfp]-[consommé anterieur] - [consommé] - [reste] - " & Int(total) & ")/[nbjour],"
                SQL = SQL & "([cfp]-[consommé anterieur] - " & Int(total) & ")/[nbjour] )"
                SQL = SQL & " AS [cout jour], "
            End If
         
        End If

        SQL = SQL & "IIf(Year([Ddo])<" & année & ",IIf(Year([Dfo])=" & année & ",[cout jour]*DateDiff('d','31/12/" & année - 1 & "',[Dfo]), "
        SQL = SQL & "IIf(Year([Ddo])<" & année & ",IIf(Year([Dfo])>" & année & ",[cout jour]*DateDiff('d','31/12/" & année - 1 & "','31/12/" & année & "'),0),0)), "
        SQL = SQL & "IIf(Year([Ddo])=" & année & ",IIf(Year([Dfo])>" & année & ",[cout jour]*DateDiff('d',[Ddo],'31/12/" & année & "'), "
        SQL = SQL & "IIf(Year([Ddo])=" & année & ",IIf(Year([Dfo])=" & année & ",[cout jour]*DateDiff('d',[Ddo],[Dfo]),0),0)),0)) AS resultat "
        SQL SQL & "FROM Budget INNER JOIN (Ressources_OP INNER JOIN OET ON (Ressources_OP.[Code Sres] OET.[Ref reseau]) "        SQL SQL & "AND (Ressources_OP.[Code OT] OET.[code ot])) ON (Budget.Projet = Ressources_OP.[Code Sres]) "        SQL SQL & "AND (Budget.Macrotache Ressources_OP.[Code OT]) "
        SQL = SQL & "WHERE (((Budget.Projet)=" & glob_sres & ") AND ((Budget.Macrotache)='" & rsbud![Macrotache] & "'));"
       
        'mdx et mamadou pbl d'une tache à 1 jours le 01/01/200. sort en erreur
        If rsbud.Fields("Macrotache").Value = "N1" Then
            Debug.Print SQL
        End If
       
        Set Rs = Db.OpenRecordset(SQL)
        'totalBud = totalBud + Rs![resultat]
        On Error Resume Next
        rsbud.Edit
        rsbud.Fields("N" & année - annéeDep + 1) = Rs![resultat]
        rsbud.Update
        Err.Clear
        Rs.Close
        'année = annéeDep + n
    Next année
    totalBud = 0
    total = 0
    rsbud.MoveNext
Loop

'mdx mise à jour des niveaux 1 avec les niveaux 2 par opération dans Budget
If nivFinancier = True Then
    Bdd = glob_DB_Aff(typaffaire).chemin
    Set Db = DBEngine.OpenDatabase(Bdd)
    On Error Resume Next
    Db.Execute "DROP TABLE [tempo ress_op1]"
    On Error GoTo 0
    '1-création table temporaire tempo ress_op1
    Db.Execute "SELECT Budget.Projet, Left([Macrotache],1) AS niv1, Sum(Budget.N1) AS b1, Sum(Budget.N2) AS b2, Sum(Budget.N3) AS b3, Sum(Budget.N4) AS b4, Sum(Budget.N5) AS b5, Sum(Budget.N6) AS b6, Sum(Budget.N7) AS b7, Sum(Budget.N8) AS b8, Sum(Budget.N9) AS b9, Sum(Budget.N10) AS b10, Sum(Budget.N11) AS b11, Sum(Budget.N12) AS b12, Sum(Budget.N13) AS b13, Sum(Budget.N14) AS b14, Sum(Budget.N15) AS b15, Sum(Budget.N16) AS b16, Sum(Budget.N17) AS b17, Sum(Budget.N18) AS b18, Sum(Budget.N19) AS b19, Sum(Budget.N20) AS b20 INTO [tempo ress_op1] From Budget Where (((Len([Macrotache])) = 2) And ((Budget.Projet) = " & glob_sres & ")) GROUP BY Budget.Projet, Left([Macrotache],1);"
    '2-mise à jour dans table Ressources_OP avec la table tempo ress_op1
    Db.Execute "UPDATE [tempo ress_op1] INNER JOIN Budget ON (Budget.Macrotache = [tempo ress_op1].niv1) AND ([tempo ress_op1].Projet = Budget.Projet) SET Budget.N1 = [b1], Budget.N2 = [b2], Budget.N3 = [b3], Budget.N4 = [b4], Budget.N5 = [b5], Budget.N6 = [b6], Budget.N7 = [b7], Budget.N8 = [b8], Budget.N9 = [b9], Budget.N10 = [b10], Budget.N11 = [b11], Budget.N12 = [b12], Budget.N13 = [b13], Budget.N14 = [b14], Budget.N15 = [b15], Budget.N16 = [b16], Budget.N17 = [b17], Budget.N18 = [b18], Budget.N19 = [b19], Budget.N20 = [b20];"
End If

End Sub

4 réponses

cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
13 mai 2008 à 17:32
Salut,

Sans répondre à ta question, il y a un truc qui m'interpelle, cette requête :
'Set Rs Db.OpenRecordset("select [date situation],[delaipaiement] from sousreseau where [code reseau] " & glob_sres)

elle fonctionne bien ?

A+
Exploreur

 Linux a un noyau, Windows un pépin
0
ddove53 Messages postés 623 Date d'inscription mardi 20 mars 2007 Statut Membre Dernière intervention 15 juin 2010
13 mai 2008 à 17:45
Non, elle marche pas c pour ça que je l'ai mis en commentaire.Si tu peux corriger l'erreur.Merci
0
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
13 mai 2008 à 20:01
Essaye cela :
Set Rs Db.OpenRecordset("select [date situation],[delaipaiement] from sousreseau where [code reseau] '" & glob_sres & "'")

A+
Exploreur

 Linux a un noyau, Windows un pépin
0
ddove53 Messages postés 623 Date d'inscription mardi 20 mars 2007 Statut Membre Dernière intervention 15 juin 2010
14 mai 2008 à 09:07
Merci bien ca marche.
Et pour ma question plus haut.Quelqu'un a une idée?
0
Rejoignez-nous