
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 :
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


0