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 56 57 58 59 60 61 62 63 64 65 66 67
| Private Sub btnactual_Click()
On Error Resume Next
Dim oDb As DAO.Database
Dim rst As DAO.Recordset
Set oDb = CurrentDb
'Initialisation des variables
vParc = ""
vNouvoRelev = ""
vAncRelev = ""
nouvoreleve = ""
ancienreleve = ""
vSortie = ""
nbrekmh = ""
consokmh = ""
'Récupération du numéro de parc issu du formulaire et ouverture du rst
vParc = Forms![F_SUIVI_CONSOMMATION]![NUMERO PARC] 'vItem = Forms![F_SUIVI_CONSOMMATION]![SF_SUIVI_CONSOMMATION]![ITEM]
Set rst = oDb.OpenRecordset("SELECT * FROM CONSOMMATION WHERE CONSOMMATION.[N° PARC] ='" & vParc & "'", dbOpenDynaset)
'-------------------------------------------------------------------------
With rst
.MoveLast 'On se position sur le dernier enregistrement du centre de coût dont numéro parc affiché et récupération relevé compteur
vNouvoRelev = .Fields("NOUVEAU RELEVE").Value 'Récupération valeur du champ NOUVEAU RELEVE
.Move -1 'Retour sur l'enregistrement précédente
vAncRelev = .Fields("NOUVEAU RELEVE").Value
.MoveLast
If .NoMatch Then 'si cet enregistrement existe, alors se positionné dessus
MsgBox "Aucun enregistrement n'a été trouvé"
Else
.Edit
.Fields("ANCIEN RELEVE").Value = vAncRelev
.Update
MsgBox "Voulez-vous actualiser les informations ?", vbInformation, "Actualisation"
End If
End With
If IsNull(vAncRelev) Then
MsgBox "Vérifier le relevé compteur précédent, ou alors le centre de coût n'est pas initialisé.", vbInformation, "Initialisation CC"
End If
Me.Refresh
'initialisation des variables avec les valeurs des champs issus du sous formulaire
nouvoreleve = Forms![F_SUIVI_CONSOMMATION]![SF_SUIVI_CONSOMMATION]![NOUVEAU RELEVE]
ancienreleve = Forms![F_SUIVI_CONSOMMATION]![SF_SUIVI_CONSOMMATION]![ANCIEN RELEVE]
vSortie = Forms![F_SUIVI_CONSOMMATION]![SF_SUIVI_CONSOMMATION]![SORTIE]
'Différentes opérations de calcul
nbrekmh = nouvoreleve - ancienreleve
consokmh = vSortie / nbrekmh
'Mises à jour et affectation des résultats aux variables
Forms![F_SUIVI_CONSOMMATION]![SF_SUIVI_CONSOMMATION]![NOMBREKMH] = nbrekmh
Forms![F_SUIVI_CONSOMMATION]![SF_SUIVI_CONSOMMATION]![CONSOMOYEN] = consokmh
CurrentDb.Execute "UPDATE CONSOMMATION SET CONSOMMATION.NOMBREKMH = " & nbrekmh & ", CONSOMMATION.[CONSOMOYEN] = " & consokmh & " where ITEM = " & vItem
'Exécution et clôture du rst
rst.Close
Set rst = Nothing
End Sub |
Partager