Re: Programatically design a form
- From: "Peter T" <peter_t@discussions>
- Date: Wed, 6 Jul 2005 17:16:46 +0100
Patrick,
As I know somewhat more about VBA than VB I'll have a go at answering your
question. We are talking VBA, not VB - right?
I understand the number of controls on a vba userform is limited to 256.
I've never tested that but have no problem with say 150. Also some report
problems with more than 64k of code in a module (so shift elsewhere).
You can certainly add controls to a userform at runtime, see example in Help
if you F1 over the .Add in say
Dim ctl as Control
Set ctl = UserForm1.Controls.Add("Forms.CommandButton.1")
Adding and removing code is more complicated. Chip Pearson, an Excel MVP,
shows how here:
http://www.cpearson.com/excel/vbe.htm
Note his comments about setting a ref to VBA Extensibility, also in Office
XP there are additional security settings to allow.
An alternative approach might be put all your controls on the form at design
stage, "Load" the form, then delete all unwanted controls, (very easy in a
few indexed loops), then "Show" the form.
However, you say you have lots of controls doing similar things. Probably
easier to use WithEvents Class(s), one set of code to handle all similar
controls. When you add a new control you just instantiate a new instance of
the class, adding a new reference to this class, in a Collection (unknown
qty) or array if pre-determined qty. Or possibly one set of controls, two
sets of WithEvents class's for different purposes and set only the relevant
class. The WithEvents code will respond same way as if the code was in the
userform module. I haven't fully explained but very easy.
Regards,
Peter T
"Patrick Pirtle" <pap@xxxxxxxxxxxx> wrote in message
news:uAMTGvjgFHA.3608@xxxxxxxxxxxxxxxxxxxxxxx
> I don't wish to hijack this thread, but the replies all sound
> as though they suggest a solution to a problem I've had
> for some time, and have had to solve through brute force.
>
> In my office, we have structural drafters and civil drafters,
> all of whom draw using a CAD program. There is an
> office application (VBA-based, not VB) that has a
> multi-page control. The problem is that, although large
> blocks of code and several of the pages are the same
> between the two groups, quite a bit is different.
>
> I originally started to write the app and displayed, or
> hid, those pages that didn't apply to whichever group
> was using the program. Here's the rub - At some point,
> I started getting out-of-memory errors. These could be
> cured by deleting some controls from my form, so I
> deduced (assumed) I had reached some limit as to the
> number of controls.
>
> After unsuccessfully trying to solve the problem, I
> split the app into TWO apps. Of course, now I have
> large blocks of code that have to be updated TWICE.
>
> So, my question is...Is it possible to somehow load an
> entire page, along with a bunch of controls ON that
> page AND the associated code, from a file on disk at
> runtime? This way, once my app starts and determines
> which group the drafter belongs to, it could load only
> the pertinent pages/controls/code into my form.
>
> TIA for any help and suggestions. And now, back to
> the regularly-scheduled thread...
>
>
> Ken Halter wrote:
> > "Peter T" <peter_t@discussions> wrote in message
> > news:OGfbm3XgFHA.2472@xxxxxxxxxxxxxxxxxxxxxxx
> >
> > You can only create "True" control arrays at design time. You can only
> > create an array of controls at runtime (not a control array)...
> > confusing? For example. Here's one of the event handlers for a "True"
> > control array. Notice the Index argument.
>
> [snip]
> --------------------------------------------------------
> The impossible just takes a little longer
>
>
.
- Follow-Ups:
- Re: Programatically design a form
- From: Patrick Pirtle
- Re: Programatically design a form
- References:
- Programatically design a form
- From: Peter T
- Re: Programatically design a form
- From: J French
- Re: Programatically design a form
- From: Peter T
- Re: Programatically design a form
- From: Ken Halter
- Re: Programatically design a form
- From: Patrick Pirtle
- Programatically design a form
- Prev by Date: Re: Using Typelib?
- Next by Date: Re: Terminate a called DLL from within the DLL
- Previous by thread: Re: Programatically design a form
- Next by thread: Re: Programatically design a form
- Index(es):
Loading