OVH Cloud OVH Cloud

problème de EOF

5 réponses
Avatar
ludivine
bonjour à toutes et à tou
j'ai une table TB contenant divers champs et plusieurs lignes. je fais une boucle while not TB.EOF dans laquelle j'initialise à zéro toutes mais valeurs (donc je fais un tour à vide), puis je compare les valeurs précédentes avec celles que j'ai trouvé précédemment, jusqu'à la fin de ma table. le problème que j'ai actuellement est le suivant
le dernier enregistrement n'est pas pris en compte, et donc mes valeurs sont faussées
comment je peux faire pour que mes valeurs soient prises en compte autrement que de repasser une dernière fois dans la boucle while not
merci d'éclairer ma lanterne
@+

5 réponses

Avatar
Raymond [mvp]
bonjour Ludivine.

ça vient de la construction de ta boucle, le movenext mal placé
certainement.
peux-tu l'afficher ici, seulement la boucle.
--
@+
Raymond Access MVP
http://access.seneque.free.fr/
http://access.vba.free.fr/
http://access2003.free.fr/
http://users.skynet.be/mpfa/ pour débuter sur le forum


"ludivine" a écrit dans le message de
news:
bonjour à toutes et à tous
j'ai une table TB contenant divers champs et plusieurs lignes. je fais une
boucle while not TB.EOF dans laquelle j'initialise à zéro toutes mais

valeurs (donc je fais un tour à vide), puis je compare les valeurs
précédentes avec celles que j'ai trouvé précédemment, jusqu'à la fin de ma
table. le problème que j'ai actuellement est le suivant :
le dernier enregistrement n'est pas pris en compte, et donc mes valeurs
sont faussées.

comment je peux faire pour que mes valeurs soient prises en compte
autrement que de repasser une dernière fois dans la boucle while not?

merci d'éclairer ma lanterne.
@+


Avatar
Eric
Bonjour Ludivine,

j'ai une table TB contenant divers champs et plusieurs lignes. je fais
une boucle while not TB.EOF dans laquelle j'initialise à zéro toutes
mais valeurs (donc je fais un tour à vide),


Pourquoi n'initialises-tu pas tes variables avant de parcourir le jeu
d'enregistrements ?

puis je compare les
valeurs précédentes avec celles que j'ai trouvé précédemment,
jusqu'à la fin de ma table.


Je comprends mal ton probleme car tu viens de réinitialiser tes valeurs.


le problème que j'ai actuellement est le
suivant : le dernier enregistrement n'est pas pris en compte, et donc
mes valeurs sont faussées. comment je peux faire pour que mes valeurs
soient prises en compte autrement que de repasser une dernière fois
dans la boucle while not? merci d'éclairer ma lanterne.



Sub Test
dim TB as DAO.Recordset
Dim Total as Double, ' autres champs à déclarer
Total = 0 : ' autres champs à initialiser
set TB = CurrentDb.OpenRecordset("TaTable")
rs.MoveFirst
While Not TB.EOF
Total= Total + TB!TonChampNumerique
TB.MoveNext
Wend
...
End Sub

Il te suffit d'un seul passage pour récupérer toutes tes valeurs.

Eric

Avatar
ludivine
la boucle est la suivante (elle est longue!!)
For MonMois=1 to 1
'RAZ des variable
While Not tb.EO
If tb!MOIS = MonMois The
If tb!NoOT <> num_OT The
num_OT = tb!NoO
tb.Edi
tb!nbint =
tb.Updat
LeDer
If MonAction = "Maintenance" The
If MonDomaine = "Commutation" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
THCO = THCO + TotalHeur
TMCO = TMCO + TotalMinut
nbintCO_ad = nbintCO_ad + Nbinterventio
Els
nbintCO_sd = nbintCO_sd +
End I
End I
If MonDomaine = "Environnement Technique" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
THET = THET + TotalHeur
TMET = TMET + TotalMinut
nbintET_ad = nbintET_ad + Nbinterventio
Els
nbintET_ad = PRnbintET_ad +
End I
End I
If MonDomaine = "Transmission" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
THTR = THTR + TotalHeur
TMTR = TMTR + TotalMinut
nbintTR_ad = nbintTR_ad + Nbinterventio
Els
nbintTR_sd = nbintTR_sd +
End I
End I
If MonDomaine = "DSLAM" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
THAD = THAD + TotalHeur
TMAD = TMAD + TotalMinut
nbintDS_ad = nbintDS_ad + Nbinterventio
Els
nbintDS_sd = nbintDS_sd +
End I
End I
If MonDomaine = "Mobiles" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
THMO = THMO + TotalHeur
TMMO = TMMO + TotalMinut
nbintMO_ad = nbintMO_ad + Nbinterventio
Els
nbintMO_sd = nbintMO_sd +
End I
End I
If MonDomaine = "Autre" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
THDI = THDI + TotalHeur
TMDI = TMDI + TotalMinut
nbintDI_ad = nbintDI_ad + Nbinterventio
Els
nbintDI_sd = nbintDI_sd +
End I
End I
TotalHeure =
TotalMinute =
Nbintervention =
Els
If MonDomaine = "Commutation" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
PRTHCO = PRTHCO + TotalHeur
PRTMCO = PRTMCO + TotalMinut
PRnbintCO_ad = PRnbintCO_ad + Nbinterventio
Els
PRnbintCO_sd = PRnbintCO_sd +
End I
End I
If MonDomaine = "Environnement Technique" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
PRTHET = PRTHET + TotalHeur
PRTMET = PRTMET + TotalMinut
PRnbintET_ad = PRnbintET_ad + Nbinterventio
Els
PRnbintET_sd = PRnbintET_sd +
End I
End I
If MonDomaine = "Transmission" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
PRTHTR = PRTHTR + TotalHeur
PRTMTR = PRTMTR + TotalMinut
PRnbintTR_ad = PRnbintTR_ad + Nbinterventio
Els
PRnbintTR_sd = PRnbintTR_sd +
End I
End I
If MonDomaine = "DSLAM" The
If TotalHeure <> 0 Or TotalMinute <> 0 The
PRTHAD = PRTHAD + TotalHeur
PRTMAD = PRTMAD + TotalMinut
PRnbintDS_ad = PRnbintDS_ad + Nbinterventio
Els
PRnbintDS_sd = PRnbintDS_sd +
End If
End If
If MonDomaine = "Mobiles" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHMO = PRTHMO + TotalHeure
PRTMMO = PRTMMO + TotalMinute
PRnbintMO_ad = PRnbintMO_ad + Nbintervention
Else
PRnbintMO_sd = PRnbintMO_sd + 1
End If
End If
If MonDomaine = "Autre" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHDI = PRTHDI + TotalHeure
PRTMDI = PRTMDI + TotalMinute
PRnbintDI_ad = PRnbintDI_ad + Nbintervention
Else
PRnbintDI_sd = PRnbintDI_sd + 1
End If
End If
TotalHeure = 0
TotalMinute = 0
Nbintervention = 0
End If
End If
MonAction = tb!Action
MonDomaine = tb!domaine
hh = Left(tb![duree], 2)
mm = Right(tb![duree], 2)
If hh > 7 Then
Nbintervention = Nbintervention + tb!nbint + Fix(hh / 7)
Else
Nbintervention = Nbintervention + tb!nbint
End If
TotalHeure = TotalHeure + hh
TotalMinute = TotalMinute + mm
End If
tb.MoveNext
If last("tb.NoOT") Then
GoTo LeDer
End If
Wend
'code
next MonMois
Avatar
Raymond [mvp]
Le movenext sur le dernier enregistrement ne peut pas déclencher le EOF. la
boucle semble bonne.

par acquit de conscience remplace:
While Not tb.EOF
tb.MoveNext
Wend
par:
Do until tb.EOF
tb.MoveNext
Loop

surtout ne rien mettre entre le next et le loop
--
@+
Raymond Access MVP
http://access.seneque.free.fr/
http://access.vba.free.fr/
http://access2003.free.fr/
http://users.skynet.be/mpfa/ pour débuter sur le forum


"ludivine" a écrit dans le message de
news:
la boucle est la suivante (elle est longue!!) :
For MonMois=1 to 12
'RAZ des variables
While Not tb.EOF
If tb!MOIS = MonMois Then
If tb!NoOT <> num_OT Then
num_OT = tb!NoOT
tb.Edit
tb!nbint = 1
tb.Update
LeDer:
If MonAction = "Maintenance" Then
If MonDomaine = "Commutation" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
THCO = THCO + TotalHeure
TMCO = TMCO + TotalMinute
nbintCO_ad = nbintCO_ad + Nbintervention
Else
nbintCO_sd = nbintCO_sd + 1
End If
End If
If MonDomaine = "Environnement Technique" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
THET = THET + TotalHeure
TMET = TMET + TotalMinute
nbintET_ad = nbintET_ad + Nbintervention
Else
nbintET_ad = PRnbintET_ad + 1
End If
End If
If MonDomaine = "Transmission" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
THTR = THTR + TotalHeure
TMTR = TMTR + TotalMinute
nbintTR_ad = nbintTR_ad + Nbintervention
Else
nbintTR_sd = nbintTR_sd + 1
End If
End If
If MonDomaine = "DSLAM" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
THAD = THAD + TotalHeure
TMAD = TMAD + TotalMinute
nbintDS_ad = nbintDS_ad + Nbintervention
Else
nbintDS_sd = nbintDS_sd + 1
End If
End If
If MonDomaine = "Mobiles" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
THMO = THMO + TotalHeure
TMMO = TMMO + TotalMinute
nbintMO_ad = nbintMO_ad + Nbintervention
Else
nbintMO_sd = nbintMO_sd + 1
End If
End If
If MonDomaine = "Autre" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
THDI = THDI + TotalHeure
TMDI = TMDI + TotalMinute
nbintDI_ad = nbintDI_ad + Nbintervention
Else
nbintDI_sd = nbintDI_sd + 1
End If
End If
TotalHeure = 0
TotalMinute = 0
Nbintervention = 0
Else
If MonDomaine = "Commutation" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHCO = PRTHCO + TotalHeure
PRTMCO = PRTMCO + TotalMinute
PRnbintCO_ad = PRnbintCO_ad + Nbintervention
Else
PRnbintCO_sd = PRnbintCO_sd + 1
End If
End If
If MonDomaine = "Environnement Technique" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHET = PRTHET + TotalHeure
PRTMET = PRTMET + TotalMinute
PRnbintET_ad = PRnbintET_ad + Nbintervention
Else
PRnbintET_sd = PRnbintET_sd + 1
End If
End If
If MonDomaine = "Transmission" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHTR = PRTHTR + TotalHeure
PRTMTR = PRTMTR + TotalMinute
PRnbintTR_ad = PRnbintTR_ad + Nbintervention
Else
PRnbintTR_sd = PRnbintTR_sd + 1
End If
End If
If MonDomaine = "DSLAM" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHAD = PRTHAD + TotalHeure
PRTMAD = PRTMAD + TotalMinute
PRnbintDS_ad = PRnbintDS_ad + Nbintervention
Else
PRnbintDS_sd = PRnbintDS_sd + 1
End If
End If
If MonDomaine = "Mobiles" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHMO = PRTHMO + TotalHeure
PRTMMO = PRTMMO + TotalMinute
PRnbintMO_ad = PRnbintMO_ad + Nbintervention
Else
PRnbintMO_sd = PRnbintMO_sd + 1
End If
End If
If MonDomaine = "Autre" Then
If TotalHeure <> 0 Or TotalMinute <> 0 Then
PRTHDI = PRTHDI + TotalHeure
PRTMDI = PRTMDI + TotalMinute
PRnbintDI_ad = PRnbintDI_ad + Nbintervention
Else
PRnbintDI_sd = PRnbintDI_sd + 1
End If
End If
TotalHeure = 0
TotalMinute = 0
Nbintervention = 0
End If
End If
MonAction = tb!Action
MonDomaine = tb!domaine
hh = Left(tb![duree], 2)
mm = Right(tb![duree], 2)
If hh > 7 Then
Nbintervention = Nbintervention + tb!nbint + Fix(hh / 7)
Else
Nbintervention = Nbintervention + tb!nbint
End If
TotalHeure = TotalHeure + hh
TotalMinute = TotalMinute + mm
End If
tb.MoveNext
If last("tb.NoOT") Then
GoTo LeDer
End If
Wend
'code
next MonMois


Avatar
Eric
Re Ludivine,

Il ne te trouveras pas les valeurs du dernier enregistrement car les
valeurs de MonAction et de MonDomaine, hh, mm ... sont définies a la
sortie de ton If End If Principal en bas de la procédure, ce qui explique
d'ailleurs ton If Last(...)
Ce qui fait qu'au 1er passage dans ce If il ne fait rien suivant qu'il
s'agisse de maintenance ou pas(MonAction). comme ces valeurs sont
définies à la fin , j'ai bien peur que tu décales tout d'1 rang.
Le movenext de fin te fait bien passer à la fin de ton jeu donc tu sors
mais tu n'as pas pu récupérer les valeurs.
Dans ta procédure, je definirai les valeurs de MonAction, MonDomaine ...
avant de tester le Der:
J'en profiterai pour réinitialiser les variables de totalisation.

De meme dans le 2eme If imbriqué, celui qui porte sur Maintenance ou le
Else, tu vides tes variables TotalHeure,... et en sortie tu mets
TotalHeure= TotalHeure+hh ou mm donc tes calculs sont pas justes, enfin
vu de loin.

Moi je testerai avec ca :
If tb!MOIS = MonMois Then
If tb!NoOT <> num_OT Then
num_OT = tb!NoOT
tb.Edit
tb!nbint = 1
tb.Update
TotalHeure = 0
TotalMinute = 0
Nbintervention = 0
MonAction = tb!Action
MonDomaine = tb!domaine
hh = Left(tb![duree], 2)
mm = Right(tb![duree], 2)
If hh > 7 Then
Nbintervention = Nbintervention + tb!nbint + Fix(hh / 7)
Else
Nbintervention = Nbintervention + tb!nbint
End If
TotalHeure = TotalHeure + hh ' à corriger si tu es passée dans le
test hh>7 peut-etre

TotalMinute = TotalMinute + mm


et apres le reste de ton code, en supprimant dans les tests les lignes
que j'ai déplacées et le IF last....(c'est une fonction perso qui te
renvoie une Booléennne ?)

Prendre une procédure au vol est difficile, mais regardes bien l'ordre
d'affectation des variables et l'ordre de totalisation.

Eric