Link to home
Start Free TrialLog in
Avatar of Noero
Noero

asked on

Look for advice in architecture VBA Access

Hello guys

I have created a class, named Tables_Support in VBA, which serves to access to the different tables to access with a collection of useful functions like (Microsoft Access):

Create_TS
Record(table selected, item)
Delete(table selected, item)
Determine_Color(table_selected): serves for conditionnal_presentation in the formular

This class contains workspace , database and recordset among lot of variables (integer string etc...)

The problem is that I create a lot of instance of this class but I never know when to delete it:
If I create it just in the Form_load function of the formular, a bug arises cause the conditional presentation of Access call Determine color before the loading of the formular. So I created a TS instance before the form is launched.
I never destroy instances cause I don't know really when and how.

Could you provide me some idea?
thanks in advance!


Avatar of Badotz
Badotz
Flag of United States of America image

You set a variable to an instance of a class, and when you are through with it, you set the variable to nothing.

You should have a Class_Initialize and Class_Terminate sub in your class; these are called automatically when you instantiate/destroy your class instance.
Avatar of Jim Dettman (EE MVE)
<<If I create it just in the Form_load function of the formular, a bug arises cause the conditional presentation of Access call Determine color before the loading of the formular. So I created a TS instance before the form is launched.>>

  OnOpen probably would have been a better choice to create instantiate TS.   However you might need to do a Me.Repaint to force creation of all the controls (not sure what your doing with your class).

  If you do create your class in the form itself, then the OnClose would be the place to destroy the instance.

Jim.

 
Avatar of Noero
Noero

ASKER

So to close TS I just make empty sub like:

Sub Class_Terminate

End Sub

No, it would be:


  Set <class vairable> = Nothing

  Your class terminate procedure will then get executed before the instance is destroyed. It's something that is part of the class.   Any cleanup tasks you have for the class (like deleting a collection used as part of the class) should be done there.

Jim.
Avatar of Noero

ASKER

I create just ONE global SS_temp, but now I have problem of multiple access, can I use the keyword static? cause the determine color function returns a bug of non existence of ss_temp, and an access denied cause already open elsewhere
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial