Dim Cn As ADODB.Connection
Dim Rs As ADODB.Recordset
Private Sub Form_Load()
Dim FechaIni As Date, FechaFin As Date
Set Cn = New ADODB.Connection
Set Rs = New ADODB.Recordset
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\ims\informesemanal.MDB;" & _
"Persist Security Info=False"
Rs.ActiveConnection = Cn
Rs.CursorType = adOpenKeyset
Rs.LockType = adLockOptimistic
'InicioSemana = FormatDateTime(Date - Weekday(Date) - 1, vbGeneralDate)
'FinSemana = FormatDateTime(Date - Weekday(Date) + 5, vbGeneralDate)
'fechaini = Format(InicioSemana, "MM-DD-YYYY")
'fechafin = Format(FinSemana, "MM-DD-YY")
FechaIni = "13/05/2011"
FechaFin = "19/05/2011"
Rs.Open "Select * From reportesemanal Where fecha BETWEEN #" & FechaIni & "# AND #" & FechaFin & "#"
If Not Rs.EOF And Not Rs.BOF Then
While Not Rs.EOF
If Rs.Fields("dia") = "viernes" Then
totalAltoriesgo = Rs.Fields("AltoRiesgo") + Rs.Fields("AltoRiesgoV")
TxtMArV = Rs.Fields("AltoRiesgo")
TxtMBrV = Rs.Fields("BajoRiesgo")
TxtVArV = Rs.Fields("AltoRiesgoV")
TxtVBrV = Rs.Fields("BajoRiesgoV")
End If
If Rs.Fields("dia") = "lunes" Then
TxtMArL = Rs.Fields("AltoRiesgo")
TxtMBrL = Rs.Fields("BajoRiesgo")
TxtVArL = Rs.Fields("AltoRiesgoV")
TxtVBrL = Rs.Fields("BajoRiesgoV")
End If
If Rs.Fields("dia") = "martes" Then
TxtMArM = Rs.Fields("AltoRiesgo")
TxtMBrM = Rs.Fields("BajoRiesgo")
TxtVArM = Rs.Fields("AltoRiesgoV")
TxtVBrM = Rs.Fields("BajoRiesgoV")
End If
If Rs.Fields("dia") = "miércoles" Then
TxtMArMi = Rs.Fields("AltoRiesgo")
TxtMBrMi = Rs.Fields("BajoRiesgo")
TxtVArMi = Rs.Fields("AltoRiesgoV")
TxtVBrMi = Rs.Fields("BajoRiesgoV")
End If
If Rs.Fields("dia") = "jueves" Then
TxtMArJ = Rs.Fields("AltoRiesgo")
TxtMBrJ = Rs.Fields("BajoRiesgo")
TxtVArJ = Rs.Fields("AltoRiesgoV")
TxtVBrJ = Rs.Fields("BajoRiesgoV")
End If
Rs.MoveNext
Wend
End If
Rs.Close
'LLAMADA A LA SUMA DE LOS TOTALES
Suma_Totales
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cn.Close
Set Cn = Nothing
End Sub
Sub Suma_Totales()
'TOTALES ALTO RIESGO
TxtTArV = Val(TxtMArV.Text) + Val(TxtVArV.Text) 'num1 + num2
TxtTArL = Val(TxtMArL.Text) + Val(TxtVArL.Text) 'num5 + num6
TxtTArM = Val(TxtMArM.Text) + Val(TxtVArM.Text) 'num9 + num10
TxtTArMi = Val(TxtMArMi.Text) + Val(TxtVArMi.Text) 'num13 + num14
TxtTArJ = Val(TxtMArJ.Text) + Val(TxtVArJ.Text) 'num17 + num18
'TOTALES BAJO RIESGO
TxtTBrV = Val(TxtMBrV.Text) + Val(TxtVBrV.Text) 'num3 + num4
TxtTBrL = Val(TxtMBrL.Text) + Val(TxtVBrL.Text) 'num7 + num8
TxtTBrM = Val(TxtMBrM.Text) + Val(TxtVBrM.Text) 'num11 + num12
TxtTBrMi = Val(TxtMBrMi.Text) + Val(TxtVBrMi.Text) 'num15 + num16
TxtTBrJ = Val(TxtMBrJ.Text) + Val(TxtVBrJ.Text) 'num19 + num20
'TOTALES GENERALES
TxtMArT.Text = Val(TxtMArV.Text) + Val(TxtMArL.Text) + Val(TxtMArM.Text) + Val(TxtMArMi.Text) + Val(TxtMArJ.Text)
TxtVArT.Text = Val(TxtVArV.Text) + Val(TxtVArL.Text) + Val(TxtVArM.Text) + Val(TxtVArMi.Text) + Val(TxtVArJ.Text)
TxtMBrT.Text = Val(TxtMBrV.Text) + Val(TxtMBrL.Text) + Val(TxtMBrM.Text) + Val(TxtMBrMi.Text) + Val(TxtMBrJ.Text)
TxtVBrT.Text = Val(TxtVBrV.Text) + Val(TxtVBrL.Text) + Val(TxtVBrM.Text) + Val(TxtVBrMi.Text) + Val(TxtVBrJ.Text)
TxtTArV.Text = Val(TxtTArV.Text) + Val(TxtTArL.Text) + Val(TxtTArM.Text) + Val(TxtTArMi.Text) + Val(TxtTArJ.Text)
TxtTBrV.Text = Val(TxtTBrV.Text) + Val(TxtTBrL.Text) + Val(TxtTBrM.Text) + Val(TxtTBrMi.Text) + Val(TxtTBrJ.Text)
End Sub