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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing record sets

Status
Not open for further replies.

SpiritOfLennon

IS-IT--Management
Oct 2, 2001
250
GB
Hi,
I have a series of sql statements some of them within nested ifs. Some of them return recordsets. However if that branch of the if statement doesn't get executed then my recordset doesn't get opened.
At the bottom of my script I have a tidy up where I close all the recordsets. However if a recordset didn't get opened it gives an error. How do I test for this and only close the recordsets that were used?
Regards
 
If ADO, I'd considered something like this:

[tt]if (not (rs is nothing)) then
if (rs.state=adstateopen) then
rs.close
end if
set rs=nothing
end if[/tt]

If some of the recordsets are meant to perform updates, you might also test .editmode and cancel a pending update prior to attempting to close.

Roy-Vidar
 
Roy,
Thanks for that I did try something similar that didn't work. However I've now realised that I was actually being bone idle so I've kicked my self up the backside and gone and closed them when they are finished with.
Regards

SOL
I'm only guessing but my guess work generally works for me.
 
If you want to continue to use the recordset then setting it = nothing after each use means that you have to instatiate it before each use. I normally set it = nothing when closing the program. If there is a better way let me know.

Also, this one line will close the record set:

Code:
     If rs.State = adStateOpen Then rs.Close
 
kimtp -- that's what RoyVidar's code above does -- it checks to see if it got instantiated, and if it was, it closes the recordset if it was open.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top