Matt said:
Hello all,
I am new to user forms and have created one using Word. I do not see
a lot of help topics for user forms and I am at a loss for some
issues, e.g. resetting the form to its defaults while in the same
session. Should I have used a different platform to create my form?
For my form, the user is to enter information into text boxes,
select/enter info from combo boxes and enter $ values for
budgeting/estimating that will need to be summed in the form.
Thank you in advance for your help!
Hi Matt,
First, there's a whole newsgroup devoted to Word userforms,
http://www.microsoft.com/communitie...t.aspx?dg=microsoft.public.word.vba.userforms.
There are two main types of forms in Word (and a third that works only in
Word 2007). The userform is one, and the other is usually called a
"protected" form, although Microsoft's naming geniuses call it an "online"
form although it has nothing to do with the Internet. For a quick intro to
the latter, see
http://www.computorcompanion.com/LPMArticle.asp?ID=22.
Each of these two types has advantages and disadvantages compared to the
other. The choice depends mostly on who needs to fill out the forms and how
the forms will be distributed to them; how much validation or error-checking
you need to build in; and how the results will be used.
A userform, as you've already discovered, is based on macro code. That means
that macros must be allowed to run in the copy of Word where the form is
being filled out. That can be a problem for unsophisticated users because
Microsoft goes a bit overboard on treating every macro (unless digitally
signed) as a malicious virus. You have to instruct users about how to enable
your userform to run if they have macro security turned up to "pit bull".
On the plus side, a userform gives you maximum flexibility in validating
data as it's entered, in modifying the form itself in response to the user's
entries, and in using controls (option buttons, combo boxes, a calendar)
that aren't available for protected forms.
A protected form doesn't necessarily have any dependence on macro code,
although it can be enhanced with macros (intro at
http://www.computorcompanion.com/LPMArticle.asp?ID=46). Validation can be
done with macros
(
http://www.word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm), but it's
more after-the-fact rather than "live".
You can also build a hybrid, where the data items are entered into a
userform, and the results are then dropped into a protected form
(
http://www.computorcompanion.com/LPMArticle.asp?ID=127).
To answer your specific question about resetting a userform to defaults, the
usual method is to create a new instance of the userform each time the user
launches it, and to destroy it (remove it from memory) as soon as its data
have been stored or used. The recommended way to do this, after defining the
userform and giving it a name (it's bad practice to keep the default
UserForm1), is to call it from a macro in a regular module this way:
Sub LaunchMyUserForm()
Dim myUF As MyUserForm
Set myUF = new MyUserForm
' optionally, initialize global variables in myUF here
myUF.Show
' optionally, use or store variables from myUF here
Set myUF = Nothing ' destroy the form
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.