Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is the problem with this code?

Status
Not open for further replies.

ishmael33

Programmer
Jul 1, 2003
3
0
0
SV
Hi to all the members list, my problem is in the unload event, when I run the form and then I click the "cancel" button the error is: "object required", perhaps if I insert a record, it works but when I click the cancel button I have the next error: "this operation is not permited when the object is open", so the bad sentences is: grs.ActiveConnection = Nothing, why I obtain this error? I copy all my code so you can read it. _Thanks a lot


Dim conn As ADODB.Connection
Dim grs As ADODB.Recordset

Private Sub aceptar_Click()
grs.AddNew
grs.Fields("apeusu") = apeusu.Text
grs.Fields("nomusu") = nomusu.Text
grs.Fields("clausu") = clausu.Text
grs.Update

End Sub

Private Sub cancelar_Click()
Unload Me
End Sub

Private Sub Form_Load()

'On Error Resume Next

Set gconn = New ADODB.Connection

gconn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & _
"\data\agenda.mdb"

gsql = "select * from users"

Set grs = New ADODB.Recordset
grs.Open gsql, gconn, adOpenKeyset, adLockOptimistic

'Fin comunicacion con la BD
End Sub

Private Sub Form_Unload(Cancel As Integer)

'cierro la tabla
grs.ActiveConnection = Nothing
gconn.Close
End Sub
 
Change this line
Dim conn As ADODB.Connection

to
Dim gconn As ADODB.Connection
 
try changing the form_unload code to


Private Sub Form_Unload(Cancel As Integer)
'cierro la tabla
grs.close
set grs = nothing
gconn.Close
End Sub

it should work



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top