Which one's preffered:Closing a Rst or setting it to Nothing

M

Mota

Hi;
Each variable has its own scope and life,and when the containing Sub or
Function or Module ends,the variable distroies and no effect of its content
remains.But it seems its not true for Recordset variables and they remains
open for a long time.I have 3 questions on this topic:
1-If we not to close a Rs,up to when it occupies memory and what time it
frees it?When the containing module or form closes,when i close my
application,or when windows shuts down?(Unlike VB,there is no command
"Unload Me" available for closing Access forms.)
2-To saving System Resources,which one is preffered: Rs.Close or Set
Rs=Nothing ?Which one frees the System Resources?
3-When we reuse a Rs variable,do we have to first close first one,and then
set it to another object?For example,is this code sufficient:
Set Rs=something
My Code Here....
Set Rs=Something Else
Another code here
Rs.Close

Or its better to use this:
Set Rs=something
My Code Here....
RS.CLOSE
Set Rs=Something Else
Another code here
Rs.Close

I will be so much grateful to anyone can help me.and thank you in advance.
 
B

BillD42

On Question 1 - DoCmd.Close acForm, "YourFormName" will close your
form.

Question 2 - Closing a recordset simply closes your access to it and
releases the data. To completely eliminate an object from memory, you must
set it to Nothing. Set rst = Nothing
Question 3 - your second statement is correct:
Set Rs=something
My Code Here....
RS.CLOSE
Set Rs=Something Else
Another code here
Rs.Close


Hope this helps,

Bill
 
M

Mota

Thank you for ur attention;
For my first question,i know how to close a form.
and i meant if for some reason i didnt set Rs variable to nothing,up to when
it occupies memory?and when it releases the memory?When application closes
or when the form closes or when windows shuts down?
Thank you.
 
B

BillD42

If you close the form in which you created the variable that references the
rst object it will release the memory. According to different articles I
have read, it may not always release the memory "immediately". That is why
it is best
to set any object variables to "Nothing" explicitly. That will remove them
immediately.

Good luck, Bill
 
M

Mota

Thank you so much for ur help.

BillD42 said:
If you close the form in which you created the variable that references the
rst object it will release the memory. According to different articles I
have read, it may not always release the memory "immediately". That is why
it is best
to set any object variables to "Nothing" explicitly. That will remove them
immediately.

Good luck, Bill

time
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top