Requete

Résolu
ddove53 Messages postés 623 Date d'inscription mardi 20 mars 2007 Statut Membre Dernière intervention 15 juin 2010 - 27 mai 2008 à 09:25
ddove53 Messages postés 623 Date d'inscription mardi 20 mars 2007 Statut Membre Dernière intervention 15 juin 2010 - 27 mai 2008 à 10:42
Slt, quelqu'un peut me dire s'il voit mon erreur?
Au fait au début je vérifie que "cfp>0", si c'est vrai je fais le calcul avec le "cfp" sinon je le fais avec "budget".
Le probéme c'est que le calcul avec le budget est juste mais pas avec le "cfp".
Si vous pouvez m'aider?

 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], "
               ' forcer les valeurs dans CP
                sql = sql & "iif(Not IsNull([N1]),([budget]-[consommé anterieur] - [consommé] - [N1]-[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], "
        
                 'forcer les valeurs dans CP
                sql = sql & "iif(Not IsNull([N1]),([cfp]-[consommé anterieur] - [consommé]-[reste] - [N1]-" & Int(total + [reste]) & ")/[nbjour],"
                sql = sql & "([cfp]-[consommé anterieur] - " & Int(total) & ")/[nbjour] )"
                sql = sql & " AS [cout jour], "
            End If
       
        End If

3 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
27 mai 2008 à 10:21
l'erreur est là:

sql = sql & "iif(Not IsNull([N1]),([cfp]-[consommé anterieur] - [consommé]-[reste] - [N1]-" & Int(total + [reste]) & ")/[nbjour],"


( & Int(total + [reste]) & ")/[nbjour],")

restructuré, ton code devient :


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(IsNull([reste]), ([budget]-[consommé anterieur] - " & Int(total) & ")/[nbjour], " & _
"([budget]-[consommé anterieur] - [consommé] - [reste] - " & Int(total) & ")/[nbjour]) " & _
"AS [cout jour], "
' forcer les valeurs dans CP
sql = sql & "iif(IsNull([N1]), ([budget]-[consommé anterieur] - " & Int(total) & ")/[nbjour] , " & _
"([budget]-[consommé anterieur] - [consommé] - [N1]-[reste]- " & Int(total) & ")/[nbjour]) " & _
"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(IsNull([reste]),([cfp]-[consommé anterieur] - " & Int(total) & ")/[nbjour], " & _
"([cfp]-[consommé anterieur] - [consommé] - [reste] - " & Int(total) & ")/[nbjour]) " & _
"AS [cout jour], "

'forcer les valeurs dans CP
sql = sql & "IIF(IsNull([N1]), ([cfp]-[consommé anterieur] - " & Int(total) & ")/[nbjour], " & _
"([cfp]-[consommé anterieur] - [consommé]-[reste] - [N1] - " & Int(total) & " + [reste]))/[nbjour]) " & _
"AS [cout jour], "
End If
End If
3
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
27 mai 2008 à 10:26
ajoutes Option Explicit

en haut de tes modules
ca t'éviteras de passer a coté ce genre d'erreurs
0
ddove53 Messages postés 623 Date d'inscription mardi 20 mars 2007 Statut Membre Dernière intervention 15 juin 2010
27 mai 2008 à 10:42
Merci.
0
Rejoignez-nous