Validate Form Field Results

C

Charlie Brown

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.
 
G

Greg Maxey

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.
 

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