Form Fields

B

Bob

I have created a MS Word Form that I want people to use
when placing an order. Is there a way that I can make
several of the form fields mandatory to fill out?

Thanks
 
G

Graham Mayor

You can test for content using a pair of macros run on exit from the field.
You'll need a similar pair of macros macro for each field you wish to test.
The following tests for content in the first field, which by default is
called Text1. Change Text1 for the name of the form field bookmark you wish
to test and the text prompt for whatever you want to say. Save the macros in
the document template - not normal.dot. The main macro uses the help
assistant to pop up the message. You could adapt to use a message box if you
prefer.

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

See http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP

Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
C

Charles Kenyon

Hi Graham,

I tried to adapt your procedures to a generic field checker and failed. The
code:

Sub ExitField()
Dim strName As String
Dim Balloon As Balloon
If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
strName = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0
Then
strName = Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If
With ActiveDocument.FormFields(strName)
If Len(.Result) = 0 Then
Beep
Application.OnTime When:=Now + TimeValue("00:00:11"), _
Name:="GoBacktoField(" & strName & ")"
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 GoBacktoField(strName As String)
ActiveDocument.Bookmarks(strName).Range.Fields(1).Result.Select
End Sub

I also tried it with a direct command to select the field rather than
calling a subroutine.

In both cases it failed when used as an on-exit macro but worked fine when
run from the VBE or stepped-through. The failure was that even though the
message displayed, the selection was the next field rather than the one that
had been checked.

I've looked at http://word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm
and http://word.mvps.org/FAQs/TblsFldsFms/GetCurFmFldName.htm.

This is the first time I've looked at the OnTime function and I'm not sure
that it allows the passing of parameters.

--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
G

Graham Mayor

I find that too :(
It needs a little more investigation and some clever heads than mine I
guess.
I'll play around with it.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP

Web site www.gmayor.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