PC Review


Reply
Thread Tools Rate Thread

Code behind objects or in separate VBA modules

 
 
=?Utf-8?B?UkxO?=
Guest
Posts: n/a
 
      3rd Aug 2007
Re: Access 2003
I learned recently that writing all vba code out in modules and referencing
form objects out there is better as opposed to the code residing inside the
form object in order to protect your code if your objects should get
corrupted.

Is this a good practice?

Example:
A module called basFormMainStartup that has the forms startup code...
vs....
Private Sub Form_Load() (which is inside the form Load event of the object
itself)

Anyone with opinions on this?

Thanks.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      3rd Aug 2007
Forms with modules tend to load more slowly than forms without modules. You
do have to load the code at some point, however. I have never heard of code
in the form or report modules causing corruption. I would think that if it
were a problem, there would not be a lot of Access applications running in
the world.

My personal practice is to put form specific code in the form /report
modules and put generic code in standard modules.
Now, with that said, there is a lot of redundant code in most applications.
For example, lets say you prefer to use your own navigation buttons. You
code the events for the buttons in each form. There are a couple of
approaches to avoid that. One is to create a standard module that includes
your standard naviagation code, and call the functions form the form module.
This only required standard naming conventions. So that if you have a button
to move to the next record, it will always be named cmdNextRec. Now you have
one set of code for n number of forms. You not only save some space, but if
you need a change, you need it in only one place. Another is similar, exept
it uses a class module with sinking events.
--
Dave Hargis, Microsoft Access MVP


"RLN" wrote:

> Re: Access 2003
> I learned recently that writing all vba code out in modules and referencing
> form objects out there is better as opposed to the code residing inside the
> form object in order to protect your code if your objects should get
> corrupted.
>
> Is this a good practice?
>
> Example:
> A module called basFormMainStartup that has the forms startup code...
> vs....
> Private Sub Form_Load() (which is inside the form Load event of the object
> itself)
>
> Anyone with opinions on this?
>
> Thanks.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public members of objects modules =?Utf-8?B?Y2F0aQ==?= Microsoft Access Form Coding 1 20th Jul 2007 09:42 PM
separate modules for each sub routine? smokiibear Microsoft Excel Programming 7 26th Jan 2005 03:36 PM
When to code in sheet or userform modules and when to use modules Tony James Microsoft Excel Programming 1 16th Dec 2004 10:02 PM
VBA & XL2K: Working with objects/class modules Mike Mertes Microsoft Excel Programming 0 1st Nov 2004 02:55 PM
Using the same variable in separate userform modules DarrenW Microsoft Excel Programming 2 11th Jul 2003 03:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.