Jumat, 27 Februari 2015

Re: [MS_AccessPros] Proper way to exit procedure if RS is empty

 

in the cleanup, I like to do this:

'~~~~~~~~~~~~~~~
On Error Resume Next
if not rs is nothing then
   rs.close
   set rs = nothing
end if
set db = nothing 'if db was set to CurrentDb
'~~~~~~~~~~~~~~~
 
if db was already nothing, it doesn't matter to set it to nothing again

the reason for On Error Resume Next is because you don't want the cleanup code to go to the error handler

If rs is not nothing but didn't open, rs.close will throw an error but it will be ignored ... so all will be good!


Warm Regards,
Crystal

Error Handling
http://www.accessmvp.com/strive4peace/Code.htm
- An error handler is a plan in case something goes wrong ...

 *
   (: have an awesome day :)
 *



On Tuesday, February 24, 2015 2:12 PM, "'Graham Mandeno' graham@mandeno.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:




Hi John/Liz
 
I think Michael Kaplan wrote an article some years ago in which he reported demonstrating that closing a Database object set to CurrentDb() resulted in a no-op.  However, closing such an object is clearly unnecessary and therefore should be avoided.
 
What is VERY necessary is closing any recordset that was opened on a locally declared Recordset object, before the procedure exits.  I'm not sure if it is still the case, but exiting a procedure without closing local recordsets used to cause Access "ghosts" – processes which disappear from the screen when Access is closed, but remain running with files open, only visible in the Task Manager.
 
Cheers,
Graham
 
 
 
From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Wednesday, 25 February 2015 07:20
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Proper way to exit procedure if RS is empty
 
 
Elizabeth-
 
Setting the db object to Nothing clears it so you don't get any memory leaks (a problem in earlier versions).  But you should NEVER close a db object set to the current database.  (Used to cause Access to blow up circa 2000 and earlier.)
 
John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)
 
 
 
On Feb 24, 2015, at 6:51 PM, glcass58@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
 
Hi John,
Thanks for your response.  I'm a little confused though.  In your example, isn't your db object set to the current db?  So you don't need to set that to nothing?  Just want to make sure I understand. :)
Thanks,
Elizabeth
 




__._,_.___

Posted by: Crystal <strive4peace2008@yahoo.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (6)

.

__,_._,___

Tidak ada komentar:

Posting Komentar