mandatory fields

J

james

Is there a way to create a form in word (using tables) to require a user to
add data to fields. I'd like to make sure that a form cannot be saved until
all data is filled out.
using word 2000, windows 2000.
 
G

Graham Mayor

If this is a form with form fields, then you can force the user to return to
an unfilled field with a macro run on exit. Change the Bookmark names to
reflect the field in question.

Thanks to Doug Robbins for the main part of the following code:

Sub ExitText1()
With ActiveDocument.FormFields("Text1")
If Len(.Result) = 0 Then
Beep
Application.OnTime When:=Now + TimeValue("00:00:01"),
Name:="GoBacktoText1"
Set Balloon = Assistant.NewBalloon
With Balloon
.Text = "No Data!" & vbCr & "You must fill in this
formfield"
.Button = msoButtonSetOK
.Animation = msoAnimationBeginSpeaking
.Show
End With
End If
End With
End Sub

Sub GoBacktoText1()
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Select
End Sub
 
J

james

Thanks for the reply, Graham! also thanks to Doug!

if I have 15 different fields that are required do I need to do 15 different
macros, or just include all the field names in the one macro?

James
 
G

Graham Mayor

You'll need a version for each field if you are to test on exit from each
field - which would encourage the user to do it right - but if you only have
the error checking on the last field, it should be possible to use a single
macro to test all the fields, and produce a suitable prompt and return the
user to the errant field.

It is simple enough to use copy and paste to duplicate the code and then
change the field names as appropriate.

Save the code in the form's template or a global template.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.dsl.pipex.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
G

Graham Mayor

The only things that immediately come to mind are to intercept the print,
save and save as commands to add code to test that the fields are all
filled, but I would hesitate to recommend this route. It would be much
simpler to add autonew/autoopen macros to pop up instructions to users to
use the form correctly. You can employ the syntax used in the original macro
to pop up the message box, with your own choice of message eg

Set Balloon = Assistant.NewBalloon
With Balloon
.Text = "Use TAB to move between fields" & vbCr & "All fields must be
completed"
.Button = msoButtonSetOK
.Animation = msoAnimationBeginSpeaking
.Show
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.dsl.pipex.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top