Visual Basic - Status conexion adobc - runtime error 3704 operation is not allowed when the object is closed

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

Status conexion adobc - runtime error 3704 operation is not allowed when the object is closed

Publicado por Martin (28 intervenciones) el 24/01/2014 22:12:06
Hola a todos, tengo un form en vb 6.0 conectado por adobc a bd sql 2008, en un formulario tengo que validar cuando el usuario capture algo en un textbox pero tengo problemas con la conexion a sql, a veces sale bien la primer consulta y en la segunda marca error, o a veces desde la primera, me marca el error de que el objecto esta cerrado pero no se como validar esto ya que estoy aprendiendo a interactuar con las bd y no se como validar en cada textbox si la conexion esta abierta o no :

ERROR :
runtime error 3704 operation is not allowed when the object is closed

MI CODIGO :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Private Sub Form_Activate()
'
CREAMOS CONEXION (las variables las declare globales en un modulo)
    Set CON = New ADODB.Connection
    With CON
        .Open "Provider=SQLOLEDB.1;Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=MIBD; Data Source=MISERVER"
    End With
'CREAMOS RECORDSET
    Set ORS = New ADODB.Recordset
    SQL = "SELECT * FROM MIBD"
    ORS.Open SQL, CON, adOpenDynamic, adLockOptimistic
    ORS.MoveFirst
    TxtIDProducto1.SetFocus
 
End Sub
 
Private Sub TxtIDProducto1_LostFocus()
 
'INICIAMOS RECORDSET
    ORS.MoveFirst
'INICIAMOS CICLO PARA VALIDAR EL ARTICULO INGRESADO
Do While Not ORS.EOF
    If ORS("ItemCode").Value = TxtIDProducto1.Text Then
        ItemCode = ORS("ItemCode").Value
        TxtCantidad1.SetFocus
        TxtDescripcion1.Text = ORS("Description").Value
        TxtPrecio1.Text = ORS("CostPriceStandard").Value
        TxtVenta1.Text = ORS("SalesPackagePrice").Value
        ORS.Close
        CON.Close
        Exit Do
        Exit Sub
    Else
        TxtIDProducto1.SetFocus
        ORS.MoveNext
    End If
Loop
If ItemCode = "" Then
    MsgBox "ERROR:  Código Incorrecto !", vbCritical, ("FORM1")
    TxtIDProducto1.SetFocus
End If
ItemCode = ""
End Sub
 
Private Sub TxtIDProducto2_LostFocus()
'INICIAMOS RECORDSET
    ORS.MoveFirst
End If
'INICIAMOS CICLO PARA VALIDAR EL ARTICULO INGRESADO
Do While Not ORS.EOF
    If ORS("ItemCode").Value = TxtIDProducto2.Text Then
        ItemCode = ORS("ItemCode").Value
        TxtCantidad2.SetFocus
        TxtDescripcion2.Text = ORS("Description").Value
        TxtPrecio2.Text = ORS("CostPriceStandard").Value
        TxtVenta2.Text = ORS("SalesPackagePrice").Value
        ORS.Close
        CON.Close
        Exit Do
        Exit Sub
    Else
        TxtIDProducto2.SetFocus
        ORS.MoveNext
    End If
Loop
If ItemCode = "" Then
    MsgBox "ERROR:  Código Incorrecto !", vbCritical, ("FORM1")
    TxtIDProducto2.SetFocus
End If
ItemCode = ""
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 107
Ha disminuido su posición en 2 puestos en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Status conexion adobc - runtime error 3704 operation is not allowed when the object is closed

Publicado por xve (208 intervenciones) el 25/01/2014 18:48:16
Hola Martin, en que linea te marca el error?

Prueba a no cerrar el objeto con CON.Close

Coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Status conexion adobc - runtime error 3704 operation is not allowed when the object is closed

Publicado por Martin (28 intervenciones) el 29/01/2014 17:56:04
Y lo intenté pero aún así recibo un error : Runtime Error 3704, La operación no está permitida cuando el objeto está cerrado, es en la primer línea del txtIDProducto1.lostfocus() adjunto el código :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Private Sub Form_Activate()
 
'DECLARAMOS VARIABLES A UTILIZAR
    Dim USER As String
    Dim REP As Integer
    Dim CONN As New ADODB.Connection
    Dim RsBASE As New ADODB.Recordset
 
'CREAMOS CONEXION A SERVIDOR : VKSVR02\VKSQL2008 BD : 006 Y TABLA : View_VK_Items DE : SQL 2008/R2
    Set CONN = New ADODB.Connection
    With CONN
       .Open "Provider=SQLOLEDB.1;Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=006; Data   Source=VKSVR02\VKSQL2008"
    End With
 
'CREAMOS RECORDSET
    Set RsBASE = New ADODB.Recordset
    SQL = "SELECT * FROM View_VK_Items"
    RsBASE.Open SQL, CONN, adOpenDynamic, adLockOptimistic
    TxtIDProducto1.SetFocus
 
End Sub
 
Private Sub TxtIDProducto1_LostFocus()
 
'INICIAMOS RECORDSET
    RsBASE.MoveFirst[ /*AQUI ME ARROJA EL ERROR*/
 
'INICIAMOS CICLO PARA VALIDAR EL ARTICULO INGRESADO
Do While Not RsBASE.EOF
    If RsBASE("ItemCode").Value = TxtIDProducto1.Text Then
        ItemCode = RsBASE("ItemCode").Value
        TxtCantidad1.SetFocus
        TxtDescripcion1.Text = RsBASE("Description").Value
        TxtPrecio1.Text = RsBASE("CostPriceStandard").Value
        TxtVenta1.Text = RsBASE("SalesPackagePrice").Value
        Exit Do
        TxtIDProducto2.SetFocus
        Exit Sub
    Else
        TxtIDProducto1.SetFocus
        RsBASE.MoveNext
    End If
Loop
If ItemCode = "" Then
    MsgBox "ERROR:  Código Incorrecto !", vbCritical, ("VASOKING")
    TxtIDProducto1.SetFocus
End If
 
End Sub
 
Private Sub TxtIDProducto2_LostFocus()
 
'INICIAMOS RECORDSET
    RsBASE.MoveFirst
 
'INICIAMOS CICLO PARA VALIDAR EL ARTICULO INGRESADO
Do While Not RsBASE.EOF
    If RsBASE("ItemCode").Value = TxtIDProducto2.Text Then
        ItemCode = RsBASE("ItemCode").Value
        TxtCantidad2.SetFocus
        TxtDescripcion2.Text = RsBASE("Description").Value
        TxtPrecio2.Text = RsBASE("CostPriceStandard").Value
        TxtVenta2.Text = RsBASE("SalesPackagePrice").Value
        Exit Do
        TxtIDProducto3.SetFocus
        Exit Sub
    Else
        TxtIDProducto2.SetFocus
        RsBASE.MoveNext
    End If
Loop
If ItemCode = "" Then
    MsgBox "ERROR:  Código Incorrecto !", vbCritical, ("VASOKING")
    TxtIDProducto2.SetFocus
End If
 
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar