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.