Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Look for advice in architecture VBA Access

Posted on 2011-10-14
6
Medium Priority
?
181 Views
Last Modified: 2012-05-12
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!


0
Comment
Question by:Noero
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 36967739
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.
0
 
LVL 58
ID: 36967868
<<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.

 
0
 

Author Comment

by:Noero
ID: 36968395
So to close TS I just make empty sub like:

Sub Class_Terminate

End Sub

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 58
ID: 36968403
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.
0
 

Author Comment

by:Noero
ID: 36968632
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
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 36968892
<<I create just ONE global SS_temp, but now I have problem of multiple access, can I use the keyword static?>>

  Static is not going to help anything; you class has properties which from call to call will be the same if your referencing the same class instance.

  From you saying that it is just ONE global SS_temp, then that sounds like it is the case.

  The problem your having is related to the class itself.  You need to either re-write Determine_Color so that it works properly for multiple users from call to call or you need to use multiple instances of the Create_TS class in your app.  An alterntaive might be to break out Determine_Color into a class of it's own and use one Create_TS class instance for the app, but multiple Determine_Color class instances.

  Hard to say without seeing what your doing.

Jim.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question