Usuario
Problemas al filtrar en un ciclo y un datagridviewer

Pregunta
-
Estoy almacenando información en tres datagridviewers de los cuales en uno almaceno el resumen de toda la información en el segundo almaceno un tipo de transacciones contables y el otro almaceno otro tipo de las cuales deben restarse al total del resumen.
Necesito identificar que transacción pertenece a que oficina y asi pueda restarse a la transacción que corresponde de lo contrario arrastra valores negativos que son el valor de la transacción del resumen menos todo lo almacenado en el datagrid de las transacciones filtradas.
Mi código es el siguiente:
If sucu = "01" Then Dim n1, x1 As Integer With Consultar Dim Cuenta, fecha22, valor2 As String Dim GranTotal As Double sucu2 = 14 For n1 = 0 To Me.DGVCatalogo.RowCount - 1 .ActiveConnection = conec4 .LockType = ADODB.LockTypeEnum.adLockOptimistic .CursorLocation = ADODB.CursorLocationEnum.adUseClient .CursorType = ADODB.CursorTypeEnum.adOpenStatic Cuenta = Me.DGVCatalogo.Item(1, n1).Value .Open("SELECT * from Cont08 where Cont08.progr = '" & sucu & "' AND Cont08.fondo = '" & Fuente & "' AND Cont08.dmovia >= '" & dia1 & "' AND Cont08.dmovia <= '" & dia2 & "' AND Cont08.mmovia >= '" & mes1 & "' AND Cont08.mmovia <= '" & mes2 & "' AND Cont08.amovia >= '" & año1 & "' AND Cont08.amovia <= '" & año2 & "' AND Cont08.numcue = '" & Cuenta & "' AND Cont08.tipo='C' AND (NOT(Cont08.numdoc like 'ACT%')) AND (NOT(Cont08.numdoc like 'CH%')) AND (NOT(Cont08.numdoc like 'D%')) AND (NOT(Cont08.numdoc like 'HE%')) AND (NOT(Cont08.numdoc like 'PDA%')) AND (NOT(Cont08.numdoc like '[TN]%')) AND (NOT(Cont08.numdoc like 'L%')) OR progr = '" & sucu2 & "' AND Cont08.fondo = '" & Fuente & "' AND Cont08.dmovia >= '" & dia1 & "' AND Cont08.dmovia <= '" & dia2 & "' AND Cont08.mmovia >= '" & mes1 & "' AND Cont08.mmovia <= '" & mes2 & "' AND Cont08.amovia >= '" & año1 & "' AND Cont08.amovia <= '" & año2 & "' AND Cont08.numcue = '" & Cuenta & "' AND Cont08.tipo='C' AND (NOT(Cont08.numdoc like 'ACT%')) AND (NOT(Cont08.numdoc like 'CH%')) AND (NOT(Cont08.numdoc like 'D%')) AND (NOT(Cont08.numdoc like 'HE%')) AND (NOT(Cont08.numdoc like 'PDA%')) AND (NOT(Cont08.numdoc like '[TN]%')) AND (NOT(Cont08.numdoc like 'L%')) Order by Cont08.progr, Cont08.numcue") If .RecordCount > 0 Then .MoveFirst() Dim n2 As Integer Me.DGVEgresos.RowCount = Me.DGVEgresos.RowCount + 2 Me.DGVEgresos.Item(0, x1).Value = Me.DGVCatalogo.Item(0, n1).Value Me.DGVEgresos.Item(1, x1).Value = Me.DGVCatalogo.Item(1, n1).Value remesas = Me.DGVEgresos.Item(1, x1).Value CSuma = 0 Total = .RecordCount Dim TotalMes As Double For n2 = 0 To .RecordCount - 1 Me.DGVEgresos.RowCount = Me.DGVEgresos.RowCount + 1 Me.DGVEgresos.Item(2, x1 + 1).Value = .Fields(13).Value Me.DGVEgresos.Item(3, x1 + 1).Value = .Fields(8).Value Me.DGVEgresos.Item(3, x1 + 1).Value = Format(Me.DGVEgresos.Item(3, x1 + 1).Value, "##,#0.00") Me.DGVEgresos.Item(4, x1 + 1).Value = .Fields(0).Value & "/" & .Fields(1).Value & "/" & .Fields(2).Value fecha22 = Me.DGVEgresos.Item(4, x1 + 1).Value 'valor2 lo tomo del dgv del resumen para hacer la comparacion del codigo contable y saber si necesito restarlo valor2 = Me.DGVEgresos.Item(3, x1 + 1).Value TotalMes = TotalMes + Me.DGVEgresos.Item(3, x1 + 1).Value x1 = x1 + 1 .MoveNext() ''Aqui se hace la comparacion, se declara una variable string, a esa variable ''se le asigna el valor del cont08 If remesas = "1011010101000000" Then 'al cumplirse la condicion de codigo contable entra al ciclo pero no diferencia que transaccion pertenece a que oficina For n11 = 0 To Me.DGVREMESAS.RowCount - 1 Valor = Me.DGVREMESAS.Item(2, n11).Value fecha = Me.DGVREMESAS.Item(4, n11).Value If fecha = fecha22 Then valor2 = valor2 - Valor Me.DGVEgresos.Item(3, x1).Value = valor2 TotalMes = TotalMes + Me.DGVEgresos.Item(3, x1 + 1).Value - Valor totalmesfondocambio = TotalMes End If Next For n12 = 0 To Me.DGVINTERESES.RowCount - 1 valor3 = Me.DGVINTERESES.Item(2, n12).Value fecha3 = Me.DGVINTERESES.Item(4, n12).Value If fecha3 = fecha22 Then valor2 = valor2 - valor3 Me.DGVEgresos.Item(3, x1).Value = valor2 TotalMes = TotalMes + Me.DGVEgresos.Item(3, x1 + 1).Value - valor3 totalmesfondocambio = TotalMes End If Next End If If CSuma < 99 Then CSuma = CSuma + (100 / Total) Me.ProgressBar1.Value = CSuma Me.Conteo.Text = CSuma & " %..." Refresh() Else Me.ProgressBar1.Value = 100 Me.Conteo.Text = "100.00 %" End If Next GranTotal = GranTotal + TotalMes Me.DGVEgresos.Item(2, x1 + 1).Value = "TOTAL MES:" Me.DGVEgresos.Item(3, x1 + 1).Value = TotalMes TotalMes = 0 Me.DGVEgresos.Item(3, x1 + 1).Value = Format(Me.DGVEgresos.Item(3, x1 + 1).Value, "##,#0.00") x1 = x1 + 2 TotalMes = 0 End If .Close() Next Me.DGVEgresos.RowCount = Me.DGVEgresos.RowCount + 1 Me.DGVEgresos.Item(2, x1).Value = "GRAN TOTAL=" Me.DGVEgresos.Item(3, x1).Value = GranTotal Me.DGVEgresos.Item(3, x1).Value = Format(Me.DGVEgresos.Item(3, x1).Value, "##,#0.00") End With End If
- Cambiado Enrique M. Montejo jueves, 1 de agosto de 2013 11:13 Acceso a datos