Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Validate Form Field Results

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Charlie Brown - 23 Jan 2008 18:44 GMT
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.

Signature

Charlie

Greg Maxey - 23 Jan 2008 19:28 GMT
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.

Signature

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

> In Word 2003, I have created an evaluation form which has several
> separate tables for each area being evaluated. The score of each area
[quoted text clipped - 18 lines]
>
> Any help on this would be greatly appreciated.
Charlie Brown - 23 Jan 2008 20:19 GMT
Snoopy says "ruff"!

Thanks for the code. It works great.
Signature

Charlie

> Charlie,
>
[quoted text clipped - 40 lines]
> >
> > Any help on this would be greatly appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.