MSHFlexGrid, agregar & eliminar
Publicado por carlos (17 intervenciones) el 15/06/2005 23:19:39
hola, tengo un problema, estoy usando un MSHFlexGrid para agragar y eliminar registro de una tabla ("CONTROL"), el problema tengo es que depues de eliminar un registro, el siguiente registro que ingreso se agrega pero no se logran ver todos los registros,; mejor aqui les mando el codigo, tiene 2 botones, un MSHFlexGrid, y 6 textbox; recuerden que el problema se presenta despues de eliminar un registro; y intenten ingrasar oteo nuevo, el ultimo registro no se logra ver. espero que me ayuden gracias
Private Sub cmdAgregar_Click()
On Error GoTo fallo
cn.Execute "insert into control values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text _
& "','" & Text4.Text & "',0,'No','" & Text5.Text _
& "','" & Text6.Text & "')"
Call CargaGrid
MsgBox "Proceso Terminado", vbInformation, "AVISO"
Exit Sub
fallo:
MsgBox Err.Description
End Sub
Sub CargaGrid()
Dim rsControl As ADODB.Recordset
Dim SQL As String
Dim fil As Integer, col As Integer
Dim f As Integer, c As Integer
Set rsControl = New ADODB.Recordset
SQL = "select Tipo,Año,mes_ini as [Mes Inicio],mes_fin as [Mes Final],[Fecha de Carga],[Fecha de Archivo] from control order by año desc"
rsControl.Open SQL, cn, adOpenStatic, adLockOptimistic
fil = rsControl.RecordCount
col = rsControl.Fields.Count
MSH.Rows = fil + 1
MSH.Cols = col
For c = 0 To col - 1
MSH.TextMatrix(0, c) = rsControl.Fields(c).Name
Next
If Not fil = 0 Then
For f = 0 To fil - 1
For c = 0 To col - 1
MSH.TextMatrix(f + 1, c) = rsControl.Fields(c)
Next
rsControl.MoveNext
Next
Else
MSH.AddItem Empty
End If
rsControl.Close
Set rsControl = Nothing
End Sub
Private Sub cmdEliminar_Click()
Dim fila As Long
Dim filadel As String, SQL As String
Dim rsTemp As New ADODB.Recordset
If MsgBox("Seguro de Eliminar", vbQuestion + vbYesNo, "AVISO") = vbYes Then
fila = MSH.Row
filadel = MSH.TextMatrix(fila, 1)
cn.Execute "delete from control where año='" & filadel & "'"
If MSH.Rows <= 2 Then 'fila = 1 Then
Dim a As Integer, i As Integer
a = MSH.Cols
For i = 0 To a - 1
MSH.TextMatrix(1, i) = "" '.RemoveItem fila
Next
Else
MSH.RemoveItem fila
End If
End If
End Sub
Private Sub Form_Load()
Call CargaGrid
MSH.FixedRows = 1
End Sub
Private Sub cmdAgregar_Click()
On Error GoTo fallo
cn.Execute "insert into control values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text _
& "','" & Text4.Text & "',0,'No','" & Text5.Text _
& "','" & Text6.Text & "')"
Call CargaGrid
MsgBox "Proceso Terminado", vbInformation, "AVISO"
Exit Sub
fallo:
MsgBox Err.Description
End Sub
Sub CargaGrid()
Dim rsControl As ADODB.Recordset
Dim SQL As String
Dim fil As Integer, col As Integer
Dim f As Integer, c As Integer
Set rsControl = New ADODB.Recordset
SQL = "select Tipo,Año,mes_ini as [Mes Inicio],mes_fin as [Mes Final],[Fecha de Carga],[Fecha de Archivo] from control order by año desc"
rsControl.Open SQL, cn, adOpenStatic, adLockOptimistic
fil = rsControl.RecordCount
col = rsControl.Fields.Count
MSH.Rows = fil + 1
MSH.Cols = col
For c = 0 To col - 1
MSH.TextMatrix(0, c) = rsControl.Fields(c).Name
Next
If Not fil = 0 Then
For f = 0 To fil - 1
For c = 0 To col - 1
MSH.TextMatrix(f + 1, c) = rsControl.Fields(c)
Next
rsControl.MoveNext
Next
Else
MSH.AddItem Empty
End If
rsControl.Close
Set rsControl = Nothing
End Sub
Private Sub cmdEliminar_Click()
Dim fila As Long
Dim filadel As String, SQL As String
Dim rsTemp As New ADODB.Recordset
If MsgBox("Seguro de Eliminar", vbQuestion + vbYesNo, "AVISO") = vbYes Then
fila = MSH.Row
filadel = MSH.TextMatrix(fila, 1)
cn.Execute "delete from control where año='" & filadel & "'"
If MSH.Rows <= 2 Then 'fila = 1 Then
Dim a As Integer, i As Integer
a = MSH.Cols
For i = 0 To a - 1
MSH.TextMatrix(1, i) = "" '.RemoveItem fila
Next
Else
MSH.RemoveItem fila
End If
End If
End Sub
Private Sub Form_Load()
Call CargaGrid
MSH.FixedRows = 1
End Sub
Valora esta pregunta


0