View Full Version : Place VBA Code in Form or in Module?


Steve R.
02-26-2009, 09:19 AM
Any preference in placing VBA code within a Form versus a Module?

I have a command button that executes a program to check the database for errors. I am in the process of updating it, and the code gets "lost" by being in the form, it would be easier to see and work on if it is in a module.

It seems to me that the VBA code in a form should be short and limited to dealing with controls on the form. So if the VBA code does not meet that criteria (the error check program), a better place would be in a module. Any thoughts?

KenHigg
02-26-2009, 09:39 AM
If it could make sense to run the code from other places in the database, like from other forms then it should go in a seperate module. If the code is tied directly with the functionality of a specific form or some of it's objects then I'd say put it in the form module. And the stand alone modules should have some kind of logic as well. If you have code that code be run in an entirely seperate database then group those routines in modules that are seperate from code written exclusively for a specific database...

Just my 2 cents :)

Steve R.
02-26-2009, 09:54 AM
Thanks, just needed some expert guidance. This program will run from only one location (form). So, it can go in the form.

KenHigg
02-26-2009, 10:06 AM
Thanks, just needed some expert guidance. This program will run from only one location (form). So, it can go in the form.


Not sure anything I post could be considered 'expert' :p Maybe a suggestion ;)