Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/06/2008, 11:35
Avatar de laluka
laluka
 
Fecha de Ingreso: julio-2007
Mensajes: 26
Antigüedad: 17 años, 9 meses
Puntos: 0
Cargar 2 tablas distintas en ListView

Hola todos , tengo un problema : tengo una conecion con ADO ,y los datos de las 2 tablas que tengo las cargo en 2 List view distintos , la primera tabla se carga correctamente en el list view , la segunda que esta en otro formulario no se carga y me da el siguiente error :"la operacion no esta permitida si el objeto esta abierto" ,entonces no se como solucionar esto, ya que solo hay una coneccion pero quiero llenar 2 tablas en distintos listview, desde ya gracias , aqui les dejo el codigo:


Public Declare Sub InitCommonControls Lib "comctl32" ()

Public cnn As New ADODB.Connection
Public rs As New ADODB.Recordset

Public ObjItem As ListItem


Sub Main()
On Error Resume Next
Call InitCommonControls
Err.Clear
Form4.Show
End Sub


Public Sub IniciarConexion()

With cnn
.CursorLocation = adUseClient
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\datos.mdb" & ";Persist Security Info=False"
End With

End Sub


Public Sub CargarListView(LV As ListView, rs As ADODB.Recordset)

On Error GoTo ErrorSub

Dim i As Integer

LV.ListItems.Clear

If rs.RecordCount > 0 Then


While Not rs.EOF

Set ObjItem = LV.ListItems.Add(, , rs(0))
ObjItem.SubItems(1) = rs!Numero
ObjItem.SubItems(1) = rs!Nombre
ObjItem.SubItems(2) = rs!Apellido
ObjItem.SubItems(3) = rs!Direccion
ObjItem.SubItems(4) = rs!Observaciones
If Abs(rs!estado) = 0 Then
ObjItem.SubItems(6) = "Masculino"
Else
ObjItem.SubItems(6) = "Femenino"
End If
ObjItem.SubItems(7) = rs!Fecha

' siguiente registro
rs.MoveNext
Wend

End If
Call ForeColorColumn(&H8000&, 0, Form4.LV)
'Call ForeColorColumn(vbRed, 6, FrmPrincipal.LV)

Exit Sub

ErrorSub:

If Err.Number = 94 Then Resume Next

End Sub


Public Sub CargarListView1(LV1 As ListView, rs As ADODB.Recordset)

On Error GoTo ErrorSub

Dim o As Integer

LV1.ListItems.Clear

If rs.RecordCount > 0 Then

' recorre el recordset
While Not rs.EOF

' añade los datos


Set ObjItem = LV1.ListItems.Add(, , rs(0))
ObjItem.SubItems(1) = rs!CI
ObjItem.SubItems(1) = rs!Nombre
ObjItem.SubItems(2) = rs!Numero
ObjItem.SubItems(3) = rs!FechaD
ObjItem.SubItems(4) = rs!fechaP




rs.MoveNext
Wend

End If
Call ForeColorColumn(&H8000&, 0, Form4.LV)
'Call ForeColorColumn(vbRed, 6, FrmPrincipal.LV)

Exit Sub

ErrorSub:

If Err.Number = 94 Then Resume Next

End Sub