Full Version: Proper Coding Practice
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
SemiAuto40
Hello All. When using VBA in an Access project I end up coming up with code for various controls and multiple events like everyone else I suppose. When I look at the VBA code for the form I notice that the sub routines are not in the same order of the controls. This makes going directly to a sub routine tedious as I scroll down through all of the code. The question is this... should I cut and paste all of the VBA code so that the subs fall in the same order as my controls - or does it not matter at all ??? I don't want to crash my database by being to anal. What is the proper coding practice?
merlenicholson
I'd certainly leave it alone, unless you really want to go crazy. To me the best way is - from the form in design, have the property window up, click on the control you want and use the property event tab to jump directly to the code on that control. With some practice it goes pretty smoothly. Also in the code window top - pick the control, then the event.

By the way - it helps tremendously to have two or more monitors. I have design on the left and use the monitor to the right for code window, so the design is never covered up. Third monitor (Portrait) I use for help pages and documentation. Way up top - monitor 4 - email, IM. I know, but hey - I'm doing this for fun.
SteveH2508
There is a superb free add-in called MZ Tools which allows you to reorder procedures in a module.
jleach
I'm in agreement with what advice has been given so far.

Within the Code Window, CTRL+F to find a procedure/event name (or part of one) is often helpful, or more often I use CTRL+Up/Down to jump down to the next procedure (it puts the cursor at the start of the procedures). It's way more accurate and quick for me to do this than try and scroll to the desired place.

hth
argeedblu
QUOTE
This makes going directly to a sub routine tedious as I scroll down through all of the code.


Are you aware of the two search boxes at the top of the VBE window? Select a control in the left one. Then select the event you want in the right. If you select General in the left, the right will display the names of all routines that are not related to a specific control.

Glenn
Galaxiom
I prefer to group my subs into blocks of similar function. The subs called by onother are often directly under the sub that called it. Of course this is not always possible when a sub is called by many others bu the calling subs are then grouped together with the called sub below that group. Most of my event procedures are quite short with the functionality broken down into other subs and functions.

Detailed structuring of the form into subforms tends to limit the amount of code in any one module so it is not difficult to find the one I am looking for. The amount of code in a module is further limited when some of the functionality common to multiple forms or controls is removed to functions in Standard Modules that are called with the form and controls as arguments.

I often use the search by highlight the name of the sub I am looking where it is being called. That term is automatically loaded when the search box is opened. If it doesn't show up in the current module the search is easily expanded to the current project.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.