Private Sub cerrar_Click()
Set Rs = CreateObject("ADODB.RecordSet")
Set CON = Application.CurrentProject.Connection
Set Rs2 = CreateObject("ADODB.RecordSet")
Set CON2 = Application.CurrentProject.Connection
c10 = "": c20 = "": c30 = "": c40 = "": C50 = "": c60 = " ": c70 = "": c80 = "": c90 = ""
c10 = "SELECT * FROM [Lecturas] ORDER BY [FECHA] "
consulta = c10
'Rs.Open consulta, CON, adOpenDynamic, adLockOptimistic
Rs.Open consulta, CON
Rs.MoveLast
Rs.MoveFirst
contador1 = Rs.fields("P1").Value
contador2 = Rs.fields("P2").Value
contador3 = Rs.fields("P3").Value
contador4 = Rs.fields("P4").Value
contador5 = Rs.fields("P5").Value
contador6 = Rs.fields("P6").Value
contador7 = Rs.fields("P7").Value
contador8 = Rs.fields("P8").Value
contador9 = Rs.fields("P9").Value
contador10 = Rs.fields("P10").Value
contador11 = Rs.fields("P11").Value
contador12 = Rs.fields("P12").Value
contador13 = Rs.fields("P13").Value
Rem condiciones
Rem bucle de recordset
Do While Rs.EOF = False
Rs.MoveNext
If Rs.EOF = True Then GoTo a
CONSULTA2 = "UPDATE Lecturas SET "
CONSULTA2 = CONSULTA2 & " Lecturas.CP1 = " & Str(Rs.fields("P1").Value - contador1) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP2 = " & Str(Rs.fields("P2").Value - contador2) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP3 = " & Str(Rs.fields("P3").Value - contador3) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP4 = " & Str(Rs.fields("P4").Value - contador4) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP5 = " & Str(Rs.fields("P5").Value - contador1) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP6 = " & Str(Rs.fields("P6").Value - contador2) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP7 = " & Str(Rs.fields("P7").Value - contador3) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP8 = " & Str(Rs.fields("P8").Value - contador4) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP9 = " & Str(Rs.fields("P9").Value - contador1) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP10 = " & Str(Rs.fields("P10").Value - contador2) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP11= " & Str(Rs.fields("P11").Value - contador3) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP12 = " & Str(Rs.fields("P12").Value - contador4) & ","
CONSULTA2 = CONSULTA2 & " Lecturas.CP13= " & Str(Rs.fields("P13").Value - contador3) & ","
CONSULTA2 = CONSULTA2 & " WHERE ((Lecturas.FECHA)= #" & Format(Rs.fields("FECHA").Value, "mm/dd/yyyy") & "# ); "
Rs2.Open CONSULTA2, CON2
contador1 = Rs.fields("P1").Value
contador2 = Rs.fields("P2").Value
contador3 = Rs.fields("P3").Value
contador4 = Rs.fields("P4").Value
contador5 = Rs.fields("P5").Value
contador6 = Rs.fields("P6").Value
contador7 = Rs.fields("P7").Value
contador8 = Rs.fields("P8").Value
contador9 = Rs.fields("P9").Value
contador10 = Rs.fields("P10").Value
contador11 = Rs.fields("P11").Value
contador12 = Rs.fields("P12").Value
contador13 = Rs.fields("P13").Value
a:
Loop
Rs.Close
End Sub