Better is something like:
Sub subADOClose( _
ByRef objToClose _
On Error Resume Next
If objToClose.State = adStateOpen then
If isObject(objToClose) then
Set objToClose = Nothing
This was you can reuse the function no matter how many recordset, command,
record or connection objects you have - you could theoretically use it for
any ADO object - as well, you aren't limited to having your recordsets
called rsShow etc
----- Original Message -----
To: "Code Clinic" <proasp_codeclinic@p...>
Sent: Wednesday, June 27, 2001 10:31 AM
Subject: [proasp_codeclinic] Re: To Close or Not To Close
: My experience is that adding a state check on both the recordset and
: connection before I close them. This works for me:
: Function closeConnection ()
: if rsShow.state = 1 then rsShow.close
: Set rsShow = Nothing
: if objDBConn.state = 1 then objDBConn.Close
: Set objDBConn = Nothing
: End Function
: This should close the recordset and connection inly when they're open,
: thus preventing any errors.
: > I don?t understand why this worked
: > In my searches I came across these two posts:
: > POST 1:
: > I keep getting an error when I try to modify a record in my database.
: > update, delete, or add all work; the changes get made, however, I still
: > this error:
: > " ADODB.Recordset error '800a0e78'
: > The operation requested by the application is not allowed if the object
: > closed.
: > /preload.asp, line 47 "
: > And here are the functions:
: > Function openConnection ()
: > Set objDBConn = Server.CreateObject("ADODB.Connection")
: > strConn = "[connection string]"
: > objDBConn.Open strConn
: > Set rsShow = Server.CreateObject("ADODB.Recordset")
: > rsShow.ActiveConnection = objDBConn
: > End Function
: > Function closeConnection ()
: > rsShow.close
: > Set rsShow = Nothing
: > objDBConn.Close
: > Set objDBConn = Nothing
: > End Function
: > POST 2:
: > Andrew,
: > I have a page that does that too, I think the recordset is open, when it
: > isn't. What I did was just deleted the lines referring to close the RS
: > setting it to nothing. Must have something to do with not explicitly
: > opening a recordset .. someone else can probably provide a more correct
: > answer based on the code you sent. (hint to the gurus that aren't in
: > Austin.)
: > *shrug*
: > Michele
: > This got me thinking about my code and sure enough the database was
: > updated even though I was getting the error. So the error was something
: > after the AddNew. Than after reading Michele?s comment I realized that
: > commenting out the close statement made sense from what the error was
: > stating. After all you can't close something that is already closed.
: > WHAT is implicitly closing the recordset? The objRS.Update command?
: * Fast, Full-Featured Microsoft® Excel Web Reports & Charts!
: A breakthrough in high performance Web application development,
: ExcelWriter 1.1 supports native Excel charting, image insertion, and
: advanced functions & formatting. One click generates presentation-quality
: Excel spreadsheets-and ExcelWriter performs over 100 times faster than the
: Excel Object. Several editions, including ExcelWriterFREE, are available.