Keep obect open when they are out of scope

W

whalesuit

Hi,
I'm working in A2K3, and I'm having a hard time understanding how to
keep an object, say an ADO recordset open after it goes out of scope.

Say I have an object, objHoldsRS that holds a private recordset.

I use a member function FillRS of this object to fill that recordset.
and then
a property get statement to getRS get the RS

Public Function InitializeObjHoldsRS(iRowID as Integer) as objHoldsRS
objInst = new objHoldsRS
objInst.FillRS(iRowID)
Set InitializeObjHoldsRS = objInst
Exit Function
End Function

Now if call this initializer from outside the module it lives in, the
objHoldsRS I have instantiated has been destroyed, evidently because I
went out of its original scope. Likewise, if I pass in the objHoldsRS
to my initialization function, eg:

Public Function InitializeObjHoldsRS(objArg as objHoldsRS, iRowID as
Integer)
Set objArg = new objHoldsRS
objArg.FillRS(iRowID)
Exit Function
End Function

My objHoldsRS object still exists because I haven't gone out of its
original scope, but the Recordset object has been closed because I went
out of that object's scope. Is there any way to avoid this
closing/destroying of objects, or do I have to pass in every object
from the scope where I want to use it?

Thanks,

Eric
 
R

Ron Hinds

You either have to pass it from the scope where you want to use it or
optionally use a Global variable. Even if you declared it with the Static
keyword it would still only be valid in that scope.
 

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