views:

212

answers:

4

I'm currently building an Excel 2003 app that requires a horribly complex form and am worried about limitations on the number of controls. It currently has 154 controls (counted using Me.Controls.Count - this should be accurate, right?) but is probably only about a third complete. The workflow really fits a single form, but I guess I can split it up if I really have to.

I see evidence in a Google search that VB6 (this usually includes VBA) has a hard limit of 254 controls in a form. However, I created a dummy form with well over 1200 controls which still loaded and appeared to work just fine.

I did get some 'out of memory' errors when trying to add specific combinations of controls though, say 800 buttons and 150 labels, leading me to think that any limit might be affected by the memory requirements of each type of control.

Does anyone have any information that might help ensure that I or, more importantly, other users with differing environments don't run into any memory issues with such a large form?

+1  A: 

No hard n soft rule...


There is no definite number of controls that VBA will limit you to.
It is entirely dependent on the system you run it on.

As a general rule of thumb:

  • Reduce the number of controls.
  • Use grid controls instead of arrays of buttons.
  • Split it into logical forms for further simplicity.
  • Use lightweight controls (handle-less controls) as they consume less memory.

Apart from this, if you still are using more than 100 controls on the screen (as you say you are) then its time you hired a new UI designer for the project.

GoodLUCK!!

PS: Do try and split the form up, if possible.
I can't imagine using any software that throws up 154 controls in one screen.
(MS-WORD comes pretty close ;-) )


UPDATE: Some stuff for your reference below...

CVS-2600Hertz
The controls are not on the screen at one time, nested multipage controls display only the sections relevant to the particular work being processed.It's just that the workflow is very complex and there is the potential to have to capture a lot of detail. I know it sounds horrible but is actually working very nicely at the moment and suits the users' needs very well.
Lunatik
Did the thing with the lightweight-controls help you out?? http://support.microsoft.com/kb/184687 This should significantly increase the number of controls you can support (even on a low-end system)
CVS-2600Hertz
Re lightweight controls, Alex K's answer seems to indicate that all VBA forms are of this type, handled by the application instead of Windows, natively. I seem to recall reading this before somewhere and it does makes sense when the restrictions on VBA compared to VB6 forms are considered.
Lunatik
In that case consider this: Any database however complex, will have some sort of structure. Some fields can always be grouped together logically. Use such a logic to spread-out the UI over several screens/forms. Allow the user the option to move front-n-back along the different forms. This ought to reduce the memory requirements of the project by several bounds. GoodLUCK!!
CVS-2600Hertz
+1  A: 

Most MSForms controls are windowless (as in they are not true windows, rather they are drawn directly by the VBA Forms engine as graphical objects) which are "light-weight" by comparison. This means you can dump more onto a Userform than you could using equivalent non-MSForms controls on a VB6 form.

I don't know what the upper limit is, but it will either be an absolute limit or a limit imposed by available resources, so if you can add 1,200 without encountering either of those & excel is behaving itself in terms of memory use you should be ok.

That said, that number of controls still seems an awful lot to present to the user at once!

Alex K.
Cheers, this matches what I'm seeing. I now have the form working sweetly with the desired number of controls in place.
Lunatik
+2  A: 

There is no hard limit for the maximum number of controls on a form. As mentioned in another answer, this will vary based on your hardware, Excel version, and operating system.

Sadly, I have had too much experience at building VBA forms with too many controls. :(

I can say, that once you get above about 200 controls, you may start noticing some strange/intermittent occurrences/errors.

One thing I have found, completely by trial and error, is that the Frame control, typically used to hold groups of radio buttons, seems to cause more problems than any other control. If I create forms without any Frame controls, I can get more controls on that form before running into trouble.

I have found that no matter how many controls you need, they can usually by categorized into different groups. If a particular group or category is going to contain more than a dozen controls (including labels) it is almost always better to have button for that category that will launch a sub-form. This really helps to reduce the complexity of the main form.

Stewbob
I know what you mean about the Frame control, I avoid them if at all possible nowadays due to the issues you highlight.
Lunatik
A: 

I try to stay away from userforms that are this big. I much prefer to use the spreadsheet to handle the data collection for things this big. If there are dependencies, then I hide/unhide rows as necessary, or use multiple sheets. I find it is an easier solution (sometimes).

guitarthrower