Jerry Bodoff said:
Hi,
I have a question about Jonathan's response. If you have
a single UserForm with multipage and a lot of controls
wouldn't the code supporting the form tend to get "un-
manageable"? Also is there a limt to the amount of code
behind a form?
There's no particular reason the code should get unmanageable. Generally,
with data capture forms like this, there are only a relatively small number
of controls that have event routines. They would be something like this.
The Click event of the Next button would increment the Value property of the
MultiPage
The Click event of the Previous button would decrement the Value property of
the MultiPage
The Change event of the Multipage would enable or disable the Next &
Previous buttons, depending on the current content of the Value property.
The UserForm_Initialize event would populate any listboxes & comboxes
present and so any other kind of initialization required.
There would probably be a Cancel button that unloads the form without doing
anything.
There would probably be an "OK" Button which would take the contents of all
the controls and write them to the appropriate locations in the document,
and then unload the form. That might be quite a long piece of code, but it
can be radically shortened by iterating though the Controls collection of
the Userform. If the target for the contents of each control is a bookmark,
then the bookmark name could be set to be the same as the name of the
control, or alternatively the bookmark name could be placed in the Tag
property of the control. In the latter case, you could use a loop like this
Dim oControl as Control
For Each oControl in Me.Controls
If Len(oControl.Tag) > 0 Then
ActiveDocument.Bookmarks(oControl.Tag).Range.InsertAfter oControl.Text
End If
Next oControl
The nice thing about that bit of code is that it ignores any control (such
as labels) where you have left the Tag property empty.
If there is a lot of code, then it may well be that there is duplication in
places, and some of the code can be taken out into a separate module and
called from the event procedures of the UserForm.