Visual Basic - Error 3705 operation is not allowed when the objec

Life is soft - evento anual de software empresarial
 
Vista:

Error 3705 operation is not allowed when the objec

Publicado por Natalie (4 intervenciones) el 13/11/2008 22:30:34
Hola Alguien me puede ayudar con el sgte error'

Error 3705 operation is not allowed when the object is open

mi cogido donde esta la conexio es este
Private Sub Cargar()

Dim CantReg As Variant

Connect.Provider = "SQLOLEDB"
Connect.Open "Driver={SQL Server};" & _
"Server=" & macForm.ConnInfo.Server & _
";Uid=" & macForm.ConnInfo.User & _
";Pwd=" & macForm.ConnInfo.pwd & _
";Database=" & macForm.ConnInfo.DB

Set Rsl = New ADODB.Recordset
Set Rs2 = New ADODB.Recordset

Cadena_SQL = "SELECT COUNT(*) as cus_name FROM OECOTIZACION_SQL"
Cadena_SQL_2 = "SELECT * FROM OECOTIZACION_SQL"

Rsl.Open Cadena_SQL, Connect, adOpenDynamic, adLockPessimistic
Rs2.Open Cadena_SQL_2, Connect, adOpenDynamic, adLockPessimistic

CantReg = Rsl.Fields("cus_name")

Rs2.MoveFirst

For i = 0 To CantReg - 1
Combo_Cliente.AddItem Rs2.Fields("cus_name")
Rs2.MoveNext

Next i


End Sub

y el codigo de consultar es este:

Private Sub Cmd_Aceptar1_Click()


Cadena_SQL = "Select * from OECOTIZACION_SQL"
StrSql = ""

If Text_Fecha.Text <> "" Then
StrSql = StrSql + "cot_date= '" & Text_Fecha.Text + " and '"
End If

If Text_Id.Text <> "" Then
StrSql = StrSql + "cot_number= '" & Text_Id.Text + " and '"
End If

If Combo_Cliente.Text <> "" Then
StrSql = StrSql + "cus_name= '" & Combo_Cliente.Text '
End If

If Text_Producto.Text <> "" Then
StrSql = StrSql + "item_no= '" & Text_Producto.Text '
End If

If Text_Product.Text <> "" Then
StrSql = StrSql + "search_desc= '" & Text_Product.Text '
End If

If Text_Especific.Text <> "" Then
StrSql = StrSql + "Especific_prod= '" & Text_Especif.Text '
End If

If Text_Presentacion.Text <> "" Then
StrSql = StrSql + "item_desc_2= '" & Cmd_present.Text '
End If

If Text_Cantidad.Text <> "" Then
StrSql = StrSql + "qty_prod= '" & Text_Presentacion.Text '
End If

If Text_Precio.Text <> "" Then
StrSql = StrSql + "prc_or_disc_1= '" & Text_Precio.Text '
End If

If Text_Validez.Text <> "" Then
StrSql = StrSql + "end_prc= '" & Text_Validez.Text '
End If

If Combo_terminos.Text <> "" Then
StrSql = StrSql + "pay_term=" & Combo_terminos.Text
End If

If Text_Direccion.Text <> "" Then
StrSql = StrSql + "addr_1= '" & Text_Direccion.Text '
End If

If Text_Reque.Text <> "" Then
StrSql = StrSql + "lead_time= '" & Text_Reque.Text '
End If

If Combo_Vendedor.Text <> "" Then
StrSql = StrSql + "cot_sales= '" & Combo_Vendedor.Text '
End If

If Text_Observ.Text <> "" Then
StrSql = StrSql + "cot_Observ= " & Text_Observ.Text
End If

If StrSql <> "" Then
Cadena_SQL = Cadena_SQL + " where " + StrSql

cadena = Cadena_SQL
desde = Len(cadena)
hasta = (desde - 5)
Cadena_SQL = Mid(cadena, 1, hasta)

End If
'MsgBox Cadena_SQL
'Connect.RecordSource = Cadena_SQl
Rs2.Open Cadena_SQL, Connect ' AQUI ME SALE EL ERROR
Fra_Funciones.Visible = True
Fra_Consultar.Visible = False
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

RE:Error 3705 operation is not allowed when the ob

Publicado por igor (633 intervenciones) el 13/11/2008 23:04:26
Pues utilizando la lógica y un poco de ingles:

operation is not allowed when the object is open

La operación no está permitida cuando el objeto está abierto

La operación es open, y el objeto Rs2 que por lo que se ve ya está abierto. Supongo que es porque en la función Cargar lo abrimos y no lo cerramos.

Siempre hay que procurar cerrar y liberar los objetos que usamos en cada función, es uno de los errores de programación más peligrosos y difíciles de depurar. Seguro que a los programadores de C,C++ con experiencia en punteros les suena de algo.
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

RE:Error 3705 operation is not allowed when the ob

Publicado por natalie (4 intervenciones) el 14/11/2008 14:05:57
Igor muchas gracias,

lo que tu dices ya lo he intentado y el erroe sigue, es ma s cuando lo cierro ya el error cambia y dice que es cuando esta cerrado.

pero de todas formas muchas gracias.
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

RE:Error 3705 operation is not allowed when the ob

Publicado por quique (63 intervenciones) el 14/11/2008 16:16:33
Bueno de entrada decirte que nunca había visto un código tan malo como ese. Sin entrar en detalles.

dónde aprendiste a programar? (es para no enviar a mis futuros hijos al mismo sitio).

y ahora al tema de la pregunta ¿dónde lo cierras ? (me refiero al recordset y en qué procedimiento).
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

RE:Error 3705 operation is not allowed when the ob

Publicado por natahalie (4 intervenciones) el 14/11/2008 16:44:24
Hola quique...

se supone que un foro es para aprender, ademas ten cuidado en lo que dices y como lo dices, que tu seas experto no quiere decir que todos los seamos.
y en donde aprendi y como no te interesa, ya lo de tus hijos es otro cuento.
pero de todas maneras gracias
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

RE:Error 3705 operation is not allowed when the ob

Publicado por quique (63 intervenciones) el 14/11/2008 17:13:19
Pero que quieres que te diga ti@....

si estás haciendo la misma pregunta en todos los foros y no quieres entender las respuestas!

igor tiene razón, si te dá error de que el recordset está abierto, es que está abierto y si está cerrado, es que está cerrado. Sólo ponle una condición If

If cerrado Then
ábrelo
Else
ciérralo
End If

No creo que sea tan dificil de entender!
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