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

VB - How to Close a Class Object

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
US
Hi,

I using a .dll on the server to preform SQL statements. I have a list view that I need to refresh (and call a function in this .dll again to run the select statement). I'm having no problems the first time thru (before refreshing). When I'm going through the code again, once I get to the line where I set my Object:

Set DBDll = CreateObject("DllName.ClassName")

I get the following error:
Operation is not allowed when object is open.

Yet if I don't use that line of code the second time through I get error 91 : Object variable or with block variable not set.

Is there some way that I need to close this object from my .dll? Or something else that might remedy this situation?

Thanks,
Ray
 
When you're done with your object variable, are you setting it to Nothing? Also, are you making any recursive calls?

Chip H.
 
I'm using the subs Class_Initialize() and Class_Terminate(), and opening the connection in the former and setting it to nothing in the latter (in the .dll). In the client, in both methods I'm using CreateObject to open and then setting it to nothing at the end of the method.

I guess I don't fully understand Class_Initialize() and Class_Terminate, they might be being automatically run more that I realize...

 
Are you running under MTS/COM+?

If so, the Class_Initialize, Class_Terminate aren't where you should be putting initialization/termination code -- it ought to be in your ObjectControl_Activate and ObjectControl_Deactivate.

Chip H.
 
No COM+ and so far I haven't tried incorporating MTS either... Thanks for your input....
 
Actually, I just found the problem; There was one of the methods in the client where I needed to set my .dll object to nothing before I called the refresh method. Thanks for your ideas, Chip
 
Glad you were able to solve your problem.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top