elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


  Mostrar Mensajes
Páginas: [1]
1  Programaciķn / Programaciķn Visual Basic / [DUDA] Error '3704' La operacion no esta permitida si el objeta esta cerrado en: 9 Octubre 2010, 18:03 pm
Bueno ante todo buenas con todos y les doy las gracias por tomarse su tiempo para leer este tema y poder ayudarme . gracias!

continuando... tngo un 2 form... FORM1 con el listview y el FORM2 con los textbox para poder modificar el listview

1° estos son las conexion que estan en un modulo
Código:
Option Explicit
Public Declare Sub InitCommonControls Lib "Comctl32" ()
Public cnn As New ADODB.Connection
Public cnn910 As New ADODB.Connection
Public RSTCliente910 As ADODB.Recordset
Public Sub ConectarTabla910()
    Set RSTCliente910 = New ADODB.Recordset
    With RSTCliente910
        .ActiveConnection = cnn910
        .CursorType = adOpenKeyset
        .Source = "Select * From clientes1010"
        .Open
    End With
End Sub


Public Sub CargarListView910(LV910 As ListView, rs As ADODB.Recordset)
       
    Dim i As Integer
    'limpia el LV
    LV910.ListItems.Clear
    On Error Resume Next
    ' si hay registros
    If rs.RecordCount > 0 Then
        ' recorre el recordset
        While Not rs.EOF
            ' aņade los datos
            Set ObjItem = LV910.ListItems.Add(, , rs(0))
                ObjItem.SubItems(1) = rs!razonsocial
                ObjItem.SubItems(2) = rs!direccion
                ObjItem.SubItems(3) = rs!marca
                ObjItem.SubItems(4) = rs!modelo
                ObjItem.SubItems(5) = rs!nēdemotor
                ObjItem.SubItems(6) = rs!aņomotor
                ObjItem.SubItems(7) = rs!nēcilindros
                ObjItem.SubItems(8) = rs!cilindrada
                ObjItem.SubItems(9) = rs!nēdeplaca
                ObjItem.SubItems(10) = rs!nēdeserieochasis
                ObjItem.SubItems(11) = rs!aņofabrica
                ObjItem.SubItems(12) = rs!combustible
                ObjItem.SubItems(13) = rs!carburador
                ObjItem.SubItems(14) = rs!configuracion
                ObjItem.SubItems(15) = rs!co
                ObjItem.SubItems(16) = rs!co2
                ObjItem.SubItems(17) = rs!o2
                ObjItem.SubItems(18) = rs!hc
                ObjItem.SubItems(19) = rs!rpm
                ObjItem.SubItems(20) = rs!cilindro1
                ObjItem.SubItems(21) = rs!cilindro2
                ObjItem.SubItems(22) = rs!cilindro3
                ObjItem.SubItems(23) = rs!cilindro4
                ObjItem.SubItems(24) = rs!detalle1
                ObjItem.SubItems(25) = rs!fecha
                ObjItem.SubItems(26) = rs!nēde
                ObjItem.SubItems(27) = rs!cit
            ' siguiente registro
            rs.MoveNext
        Wend
       
    End If
    Call ForeColorColumn(&H8000&, 0, FrmPrincipalClau9.LV910)

   
    Exit Sub
   
ErrorSub:
   
    If Err.Number = 94 Then Resume Next
   
End Sub

Public Sub IniciarConexion910()
    With cnn910
       
        .CursorLocation = adUseClient
        .Open "Provider=SQLOLEDB.1;Password=qweqwe;Persist Security Info=True;User ID=omar;Initial Catalog=BASEFINAL;Data Source=SERVIDOR"
       
    End With
End Sub

2° este es como hago paa que cargue el listview en el FORM1

Código:
Dim cnn99      As New ADODB.Connection
' este editar es para q vaya al FORM2
Private Sub editar10()
    Dim i As Integer
    On Error Resume Next
    ' verifica que hay datos en el ListView y que hay uno seleccionado
    If (LV910.ListItems.Count = 0) Then
       MsgBox "No hay ningún regisro para editar", vbInformation
    Exit Sub
    End If
    If (LV910.SelectedItem Is Nothing) Then
       MsgBox "Debe seleccionar previamente un registro para poder editarlo", vbInformation
    Exit Sub
    End If
    With FrmImpresionCIT1210
        ' obtiene el elemento seleccionado
      .lblID = LV910.SelectedItem.Text
    For i = 1 To 27
      .Text1(i).Text = LV910.SelectedItem.ListSubItems(i).Text
    Next
      .Text1(25) = LV910.SelectedItem.ListSubItems(25).Text
      .IdRegistro = LV910.SelectedItem.Text
      .ACCION12 = editar_registro12
      .Show
    End With
End Sub
' este lv910 es el nombre del listview y cuando le hago doble clic activa otros botnes en el otro form
Private Sub LV910_DblClick()
    Call editar10
    FrmImpresionCIT1210.cmdSave10.Visible = True
    FrmImpresionCIT1210.Command010.Visible = True
End Sub
' este es para activar el listview para que cargue los datos... ya que el FORM1
' cuando se activa no aparece nada y este boton hace que cargue el list view
Private Sub ChameleonBtn10_Click()
    Busqueda10.Visible = True
    LV910.Visible = True
    Call IniciarConexion910
    Call ConectarTabla910
    Call CargarListView910(LV910, RSTCliente)
    Label3 = ChameleonBtn10.Caption
Call bloquear
End Sub

' este boton es para cerrar la conexion
Private Sub ChameleonBtn99_Click()
    cnn99.Close
    Call invisible
    Call desbloquear
    Label3 = "Por Escoger"
End Sub

3° y este es el FORM2 que cargan los textbox para poder modificar los datos de cada item

Código:
Option Explicit
Dim cnn As New ADODB.Connection
Dim cnn910 As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim RSTCliente910 As ADODB.Recordset
Enum EACCION12
    AGREGAR_REGISTRO12 = 0
    editar_registro12 = 1
End Enum
'Dim CNN As New ADODB.Connection
Public ACCION12 As EACCION12

'Dim rs As ADODB.Recordset
Public IdRegistro
Private Sub cmdSave10_Click()
'  On Error GoTo ErrorSub

    If cnn910.ConnectionTimeout = True Then
    Call IniciarConexion910
    End If
   
    Text1(27).Text = 12
    Select Case ACCION12
    Case editar_registro12
    cnn.Execute "UPDATE Clientes1010 set razonsocial= '" & Text1(1) & "',direccion= '" & Text1(2) & "',marca= '" & Text1(3) & "',modelo= '" & Text1(4) & "',nēdemotor= '" & Text1(5) & "',aņomotor= '" & Text1(6) & "',nēcilindros= '" & Text1(7) & "',cilindrada= '" & Text1(8) & "',nēdeplaca= '" & Text1(9) & "',nēdeserieochasis= '" & Text1(10) & "',aņofabrica= '" & Text1(11) & "',combustible= '" & Text1(12) & "',carburador= '" & Text1(13) & "',configuracion= '" & Text1(14) & "',co= '" & Text1(15) & _
                                    "', co2= '" & Text1(16) & "',o2= '" & Text1(17) & "',hc= '" & Text1(18) & "',rpm= '" & Text1(19) & "',cilindro1= '" & Text1(20) & "',cilindro2= '" & Text1(21) & "',cilindro3= '" & Text1(22) & "',cilindro4= '" & Text1(23) & "',detalle1= '" & Text1(24) & "',fecha= '" & Text1(25) & "',nēde= '" & Text1(26) & "',cit= '" & Text1(27) & _
                                    "' where Cod = " & IdRegistro & "'"
   
    End Select
   
    RSTCliente.Requery 1
   
    Call CargarListView910(FrmPrincipalClau9.LV910, RSTCliente910)

    DoEvents
    Unload Me
    Set frmImpresionCIT12 = Nothing
Exit Sub
'ErrorSub:
'MsgBox Err.Description

End Sub
Private Sub Form_Load()
    Call Conectar
    Call Conectautos
    Call Conectcombustible
    Call ConectarTabla910
End Sub
Private Sub Command2_Click()
ListBoxEx1.Visible = True
End Sub
Public Sub Conectautos()
'   On Error Resume Next
    Set RSTautos = New ADODB.Recordset
    With RSTautos
        .ActiveConnection = CN
        .CursorType = adOpenKeyset
        .Source = "Select * From autos"
        .Open
       
        If .RecordCount > 0 Then
            .MoveFirst
            Do While Not .EOF
                ListBoxEx1.AddItems !autos, True
                .MoveNext
            Loop
        End If
    End With
End Sub
Private Sub ListBoxEx1_DblClick()
    Text1(3).Text = ListBoxEx1.GetItemCaption(ListBoxEx1.SelectedIndex)
    ListBoxEx1.Visible = False
End Sub
Private Sub Command3_Click()
ListBoxEx2.Visible = True
End Sub
Public Sub Conectcombustible()
'On Error Resume Next
    Set RSTcombustible = New ADODB.Recordset
    With RSTcombustible
        .ActiveConnection = CN
        .CursorType = adOpenKeyset
        .Source = "Select * From combustible"
        .Open
       
        If .RecordCount > 0 Then
            .MoveFirst
            Do While Not .EOF
                ListBoxEx2.AddItems !combustible, True
                .MoveNext
            Loop
        End If
    End With
End Sub
Private Sub ListBoxEx2_DblClick()
    Text1(12).Text = ListBoxEx2.GetItemCaption(ListBoxEx2.SelectedIndex)
    ListBoxEx2.Visible = False
End Sub

bueno el problema es que cuando cargo el listview se me cierra la conexion y cuando trato de hacer el update me sale operacion no permitida si el objeto esta cerrado
y ese es el problema q tngo , gracias por leer y tratar de ayudarme con darme una solucion gracias
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines