Recordset dilemma

TomL

Registered User.
Local time
Today, 11:17
Joined
Aug 11, 2010
Messages
18
I'm having a problem dealing with a recordset closing. The problem occurs when I got an error message.
"Operation is not allowed when the object is open."
So I get the bright idea to test if the recordset (rs) is open as in
if rs.state = 1 then
rs.close
end if
But, when it executes this line I get an error "Operation is not allowed in this context".
Seems like I'm dammed if I do and dammed if I don't. Is there some other way to handle the recordset state?
I have the recordset defined in a module as in:
Dim rs As New ADODB.Recordset
I assumed that once declared all I would have to do is open and close the recordset. Can someone explain the error messages and their cause.
How do I handle a situation where the code encounters an error condition in the main body of code and goes to an error handler? Should I be testing to see if the recordset is open in the event handler and if so close it or will the recordset close when the sub procedure closes?

Thanks,
Tom
 
The problem occurs when I got an error message.
"Operation is not allowed when the object is open."
So I get the bright idea to test if the recordset (rs) is open as in
if rs.state = 1 then
rs.close
end if
But, when it executes this line I get an error "Operation is not allowed in this context".

Normally you get that error when trying to close if it is NOT open. (Maybe you just wrote it backwards here.)
I use virtually identical code to test for being open when I want to close and have never had a problem.

Are you sure some other line is not causing the error? Could it be busy executing when you are trying to close? I have not seen the context error myself.

Try commenting out everything else in the procedure or running just the closing snippet in a separate procedure.
 
Thanks for the reply. I'm going to go back and give this some more time and see if I can find out what's happening.
Tom
 

Users who are viewing this thread

Back
Top Bottom