[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Advice RE: Structuring and Organizing Standard Modules (Access 2010)

Posted on 2012-09-06
13
Medium Priority
?
606 Views
Last Modified: 2012-09-07
Hi everyone,

I have tried to structure my standard modules with the following in mind:
keep procedures that  will be called at a specific time together (for ex: start-up procs) in order to spread out the 'apparent' load time
keep related procedures together
keep larger, specialized procedures that may never be called separate (in their own module)
if the above three can be followed, keep the same type of procedure together (ex: msgs that are reused) so that they are easy to find and edit
keep specialized procedures separate for code maintenance
keep frm/rpt procedures that are only called when that frm/rpt is open, on the frm/rpt --even if public-- so that they are not kept in memory

I don't know very much about how modules are loaded in the context of memory usage, so do you have any advice or comments on the best way to structure things?

And also, in my GlobalVars module (storing public vars and constants), I have included a function that sets any temp vars (gets called during startup), because they are used in the same way. Does this sound okay?

I realize that this may be a matter of personal preference, but any advice would  be much appreciated.

Thanks in advance :)
SD

PS (not using any custom class modules yet)
0
Comment
Question by:shelldee
  • 6
  • 4
  • 3
13 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 800 total points
ID: 38374284
<<I don't know very much about how modules are loaded in the context of memory usage, so do you have any advice or comments on the best way to structure things?>>

 You've answered this yourself with your bullet points:  anything in a standard or class module is loaded first time it's used and stays resident for the life of the app.

 Form/Report modules are cleared when the form or report closes.

 So following your outline yeilds the best results.

<<And also, in my GlobalVars module (storing public vars and constants), I have included a function that sets any temp vars (gets called during startup), because they are used in the same way. Does this sound okay?>>

  Yes.  If your going to use Global variables, it's cleanest to set/get them through a procedure.  With that said, I've also done it without<g>.   If your consistent in naming, I don't find it anymore difficult and achieve the same thing with a lot less clutter.

  The door you open however is that you accidently use a variable you didn't mean to, so it's possible to introduce a bug that way, but then you can call the wrong procedure to (not as likely, but possible).

<<PS (not using any custom class modules yet) >>

  Except for limited situations, I believe class modules are a waste in VBA because it's not a fully OOP based language, but simply object based (it lacks full inheritance). So the true power of classes is doesn't come into play.

  What I've found over the years is that with some ad-hoc utilities for updating properties, I can pretty much do everything I could with classes and not get the overhead.   And of course anyone that's developed in a fully OOP based language knows that using classes has their own set of problems as well (such as composite vs concrete classes).

FWIW,
Jim.
0
 

Author Comment

by:shelldee
ID: 38374415
Thanks Jim,

Just wanted to double check that I wasn't missing anything.  :)

Re Global Vars;
I'm using only the TempVar collection and 2 object variables to cache the ribbon and to use the CurDb function from your  article
CurrentDB vs DbEngine(0)(0)
Thank you very much for posting it. It was easy to follow and I'm using your function all of the time now.

Re Class Modules;
Thank you for the info. I was planning on learning more about them this winter, esp sub-classing (for form events like Form_Error)... so I will have more questions regarding your last paragraph, and 'ad-hoc utilites for updating properties', down the road.

Thanks again, for your help :)
Shelley
0
 
LVL 75
ID: 38374439
"Form/Report modules are cleared when the form or report closes."
Jim ... what do you  mean by 'cleared' ?
0
Technology Partners: 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!

 
LVL 75
ID: 38374447
"  Except for limited situations, I believe class modules are a waste in VBA because it's not a fully OOP based language, "
I disagree, especially since Form & Report modules are Class modules.

I have several Class modules that one would be hard pressed to duplicate with standard modules.

mx
0
 
LVL 58
ID: 38374648
<<"Form/Report modules are cleared when the form or report closes."
Jim ... what do you  mean by 'cleared' ?>>

 Memory used by the modules is re-claimed.

Jim.
0
 

Author Comment

by:shelldee
ID: 38374885
Thanks DatabaseMX for adding your thoughts,

I was thinking that a class module might be an alternative for TempVars that hold current user information that is displayed in headers (or Ribbon). Setting controls on the persistent form wouldn't work in this current project's split environment because I have a procedure that that allows for changing backends, without the user logging off. (I hope that this isn't a bad idea--because I've noticed that the old laccdb file isn't always destroyed right away... but that's another topic.) Anyways, I'll look foward to hearing more about 'custom', (ie not frm/rpt) class modules in the future.

Regarding module loading -- I think the unknown for me has to do with overhead (size & number of mods)-- and as I get more experience, hopefully I'll be able to gauge better.

Thanks again, for taking the time to respond :)
Shelley
0
 
LVL 58
ID: 38375888
Shelley,

<<Regarding module loading -- I think the unknown for me has to do with overhead (size & number of mods)-- and as I get more experience, hopefully I'll be able to gauge better.>>

  Honestly, in this day and age, it's rather an insignificant thing.  A "typical" FE (and I'm using that term loosly) is some where around 10 - 20MB in total; that's not a ton of memory.

  Of more concern I think would be what you store in memory.  For example, pulling recordsets into memory, large array's, etc will have far more impact on memory usage then what VBA is doing with it's house keeping.

Jim.
0
 
LVL 58
ID: 38375968
@mx,

<<"  Except for limited situations, I believe class modules are a waste in VBA because it's not a fully OOP based language, "
I disagree, especially since Form & Report modules are Class modules.>>

  You didn't include the rest of the statement.  There are cases in VBA where it makes since to use class modules, which is basically anytime you have a multiple of something, say printers for example.  You might even go as far as creating custom classes for each of your record types.  Their easier then arrays by far for stuff like that.  But beyond that? You can't do much with them.  

  VBA is object based, not object orientated and that's a big difference.  Not sure if you've ever worked in a fully OOP compliant language, but the difference is substantial.

  With an object orientated language for example, you can start with a base class for a text control, subclass that for a framework level control, then subclass that for an application specific control if you need to.  At each subclassing, all the PEMs (Properties, Events, and Methods) all follow and with each subclassing, you can modify the behaviour.

 Another way I can do things is to start off with a base class for a text control, subclass that and then apply additional PEMs to create a Date/Time control, then subclass that for framework level and application level specific controls.

If I then make a change in the base class, that follows through to the date/time control.  

 Nothing like that exists in VBA, which is why I say classes in VBA are not really worth the effort as you can't really use the power of classes the way they should be used.

 Have you ever tried to hook up a custom text box class to text controls on every form in your application just so you can sink an event in your custom class?  It's a lot of work and a lot of overhead.

 But from a functional perspective, ad-hoc utilities that allow you to update the existing PEM's on objects gives you that capability and without all the additional plumbing.

 I'm not saying that classes are a bad thing in VBA, but I feel that the cases where you can really use them well are limited and for the most part, you can live without them.

 Proof of point; have you *ever* seen an Access app that was totally class based?   I haven't.  How many Access apps have you seen that have more classes then standard code?  Few and far between would be my guess (I've never seen one yet).

 Classes just don't work in VBA like they should because it lacks implementation inheritance, which is what makes it object based rather then object orientated.

FWIW,
Jim.
0
 

Author Comment

by:shelldee
ID: 38376353
Thanks, Jim, for posting the follow-up. Very helpful.
S
0
 
LVL 75
ID: 38377352
"which is why I say classes in VBA are not really worth the effort as you can't really use the power of classes the way they should be used."
All the classes I've made are definitely worth the effort.   On the other hand, I've never needed to " Have you ever tried to hook up a custom text box class to text controls on every form in your application just so you can sink an event in your custom class? "

Further, I've been able to do some amazing things in Access/VBA/DAO ... in fact, I've always been able to do anything that I wanted and/or needed to do.  A LOT of people clearly underestimate the power of the platform.  The non existent inheritance stuff has never been a issue for me either.

" Proof of point; have you *ever* seen an Access app that was totally class based?"
No, but why would it need to be ?

"  Honestly, in this day and age, it's rather an insignificant thing."
I do totally agree with that.  I have never seen a issue with module loading whatsoever, especially on today's systems.

mx
0
 
LVL 58
ID: 38377918
<<" Proof of point; have you *ever* seen an Access app that was totally class based?"
No, but why would it need to be ? >>

 The point I was getting at is that if classes worked well, you should see a lot more of them no?  But you don't; why not?

 Because in VBA with most situations, they don't really give you an advantage vs the cost of working with them.  There are a few instances where they work well, but overall for the most part it's just a lot of extra overhead.

 VFP on the other hand is done typically with nothing but classes even though you can write straight linear code if you want.

  Classes in a fully OOP compliant language give you a tremendous amount of power and control over what happens and when.

<<Further, I've been able to do some amazing things in Access/VBA/DAO ... in fact, I've always been able to do anything that I wanted and/or needed to do.  A LOT of people clearly underestimate the power of the platform.  The non existent inheritance stuff has never been a issue for me either.>>

 Really?  You like working with continious forms and all the limitations?  The lack of a native grid control that works well is a killer and always has been.  Datasheets have improved somewhat, but it's still hard to do things with child records.   Just look for a scheduling app in Access for something like a doctors office; I'd be shocked if I saw one written with Access.

 I don't disagree that Access has been able to do a lot of things that people never think it capable off doing, but like anything else, it's not without problems or limitations.  

 I'd love to write 3 tier apps with Access, but it simply can't be done.

 But were getting off the subject.

Jim.
0
 
LVL 75
ID: 38378202
"But you don't; why not?"
But I do.  Many of my developer colleagues use classes.  
I think a lot of Access peeps simply do not understand them.

" You like working with continious forms and all the limitations?  "
IF ... I find a limitation, I find another way to do it. I go to the web and look for ideas, cool stuff that is being done on sites, and emulate that.

Remember .... most everyone said you can't and should not ... run Access on a WAN. OOPS!

But, like you said ... we are drifting ...

mx
0
 
LVL 58
ID: 38378482
<<Remember .... most everyone said you can't and should not ... run Access on a WAN. OOPS! >>

LOL "WAN" in name only...there's not a lot of LANs that run at that speed.

<<But, like you said ... we are drifting ...>>

Yup.

Jim.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

829 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