In Word 2003, I have created an evaluation form which has several separate
tables for each area being evaluated. The score of each area is entered into
a form field. There are 13 fields, each having its own bookmark name; score1,
score2, score3, etc. The user is to enter a score between 1 and 3 or leave it
blank.

To validate the fields are blank or not greater than 3, I have written this
code;

If ActiveDocument.FormFields("score1").Result > 3 Then
MsgBox "The score must be between 0 and 3.", vbCritical, "Score Check"
ActiveDocument.Bookmarks("score1").Range.Fields(1).Result.Select
End If

It has two problems;
1. It gets a type mismatch error if the field is blank. I am having trouble
figuring out how to checking for NULL fields.
2. Rather than repeat the code 13 times, I would like the code to loop
through all the score fields.

Any help on this would be greatly appreciated.

--
Charlie

Re: Validate Form Field Results by Greg

Greg
Wed Jan 23 11:28:58 PST 2008

Charlie,

Something like this:

Sub Test()
Dim oFF As FormField
Dim oFFs As FormFields
Set oFFs = ActiveDocument.FormFields
For Each oFF In oFFs
If InStr(oFF.Name, "score") > 0 Then
Select Case oFF.Result
Case Is = 0, 1, 2, 3
MsgBox "Sat"
Case Else
MsgBox "The value in " & oFF.Name & " must be ""0, 1, 2, or 3"""
End Select
End If
Next
End Sub

Say hello to Lucy and the gang for me.


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Charlie Brown wrote:
> In Word 2003, I have created an evaluation form which has several
> separate tables for each area being evaluated. The score of each area
> is entered into a form field. There are 13 fields, each having its
> own bookmark name; score1, score2, score3, etc. The user is to enter
> a score between 1 and 3 or leave it blank.
>
> To validate the fields are blank or not greater than 3, I have
> written this code;
>
> If ActiveDocument.FormFields("score1").Result > 3 Then
> MsgBox "The score must be between 0 and 3.", vbCritical,
> "Score Check"
> ActiveDocument.Bookmarks("score1").Range.Fields(1).Result.Select
> End If
>
> It has two problems;
> 1. It gets a type mismatch error if the field is blank. I am having
> trouble figuring out how to checking for NULL fields.
> 2. Rather than repeat the code 13 times, I would like the code to loop
> through all the score fields.
>
> Any help on this would be greatly appreciated.



Re: Validate Form Field Results by CharlieBrown

CharlieBrown
Wed Jan 23 12:19:02 PST 2008

Snoopy says "ruff"!

Thanks for the code. It works great.
--
Charlie


"Greg Maxey" wrote:

> Charlie,
>
> Something like this:
>
> Sub Test()
> Dim oFF As FormField
> Dim oFFs As FormFields
> Set oFFs = ActiveDocument.FormFields
> For Each oFF In oFFs
> If InStr(oFF.Name, "score") > 0 Then
> Select Case oFF.Result
> Case Is = 0, 1, 2, 3
> MsgBox "Sat"
> Case Else
> MsgBox "The value in " & oFF.Name & " must be ""0, 1, 2, or 3"""
> End Select
> End If
> Next
> End Sub
>
> Say hello to Lucy and the gang for me.
>
>
> --
> Greg Maxey/Word MVP
> See:
> http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>
>
> Charlie Brown wrote:
> > In Word 2003, I have created an evaluation form which has several
> > separate tables for each area being evaluated. The score of each area
> > is entered into a form field. There are 13 fields, each having its
> > own bookmark name; score1, score2, score3, etc. The user is to enter
> > a score between 1 and 3 or leave it blank.
> >
> > To validate the fields are blank or not greater than 3, I have
> > written this code;
> >
> > If ActiveDocument.FormFields("score1").Result > 3 Then
> > MsgBox "The score must be between 0 and 3.", vbCritical,
> > "Score Check"
> > ActiveDocument.Bookmarks("score1").Range.Fields(1).Result.Select
> > End If
> >
> > It has two problems;
> > 1. It gets a type mismatch error if the field is blank. I am having
> > trouble figuring out how to checking for NULL fields.
> > 2. Rather than repeat the code 13 times, I would like the code to loop
> > through all the score fields.
> >
> > Any help on this would be greatly appreciated.
>
>
>