Closing Recorsets Left Hanging Open

grovelli

Registered User.
Local time
Today, 01:37
Joined
Apr 3, 2005
Messages
16
In the Click event for the Comando50 button on the startup form of the attached mdb, I'm trying to use the line
If rst.State = adStateOpen Then rst.Close
but I get the
Ado runtime error 3219: The operation requested by the application is not allowed in this context.
when the code executes that line.
How do you then close recordsets left open?
(The rst recordset is left open if I try inserting a date that's already present)
 

Attachments

I would just set On Error Resume Next and do it!
 
Hi,
I cannot resume the code at the next instruction because I need the line
If rst.State = adStateOpen Then rst.Close
to work so as to close the recordset.
 
I personally grovelli, like many programmers do,
have one exit point, where they do all their clean up.

Sub FindName()
On Error GoTo xxx

Dim rst As New AdODB.Recordset
rst.Open "SELECT......
Do Until....
...
Loop

CleanUp:
rst.Close
set rst = Nothing
Exit Sub

xxx:
MsgBox err.Number & vbcrLf & err.Description
Resume CleanUp
End Sub
 

Users who are viewing this thread

Back
Top Bottom