Recordset Testing Problems

  • Thread starter Thread starter Eddy
  • Start date Start date
E

Eddy

Is there a means to test if a recordset is open when it is in fact not open.
I open recordsets with code behind forms. If an error occurs in the code
before the recordset is open, when I try to close it in the under the exit
portion of the code I an Object Variable Not Set error. I tried to test
with an if then IF rs then or If rs=Nothing then both gave me errors.
Thanks
 
Depends if it is an ADO recordset or a DAO recordset. With an ADO recordset,
test the State property of the recordset. A DAO recordset doesn't have a
State property, so I use a Boolean variable - I set it to True immediately
after opening the recordset, and set it to false immediately after closing
the recordset. In my error handler, I close the recordset if the variable is
True.
 
In addition to my earlier post, to test for Nothing you need to use "Is"
instead of "=", e.g. If rst Is Nothing Then ...
 
Back
Top