Bookmark check

F

Frenk Nijssen

Hi,

I have created a form as a word template, when the user wants to print the
form i would like to check if he filled in the mandatory Formfields.

Is there code available to do this in a loop? all Formfields are bookmarked,
the ones that i like to check if they are filled out, end with "_man"

Further i would like to point the user to the formfield that he hasn't
filled out with a Msgbox "MyFormfieldname - _man".

I am fairly new at this, so if anyone can point me in the right direction
that would by great.

Thanks
Frenk
 
J

Jean-Guy Marcil

Frenk Nijssen was telling us:
Frenk Nijssen nous racontait que :
Hi,

I have created a form as a word template, when the user wants to
print the form i would like to check if he filled in the mandatory
Formfields.

Is there code available to do this in a loop? all Formfields are
bookmarked, the ones that i like to check if they are filled out, end
with "_man"

Further i would like to point the user to the formfield that he hasn't
filled out with a Msgbox "MyFormfieldname - _man".

I am fairly new at this, so if anyone can point me in the right
direction that would by great.

Try this:

'_______________________________________
Sub FilePrint()

'To intercept File > Print and CTRL-P
If AllFormfieldsOK Then
Dialogs(wdDialogFilePrint).Show
End If

End Sub
'_______________________________________

'_______________________________________
Sub FilePrintDefault()

'To intercept the Standard toolbar button
If AllFormfieldsOK Then
ActiveDocument.PrintOut
End If

End Sub
'_______________________________________

'_______________________________________
Private Function AllFormfieldsOK() As Boolean

Dim myFormField As FormField

AllFormfieldsOK = True

For Each myFormField In ActiveDocument.FormFields
'Only check formfields that are mandatory
'use LCase in case "_Man" was used in text
If LCase(Right(myFormField.Name, 4)) = "_man" Then
'Use Trim in case there are spaces and no other character
If Trim(myFormField.Result) = "" Then
MsgBox "You must enter information in this field.", _
vbExclamation, "Data missing"
myFormField.Range.Fields(1).Result.Select
AllFormfieldsOK = False
Exit Function
End If
End If
Next

End Function
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
F

Frenk Nijssen

Thanks a lot Jean-Guy,

Perfect piece of code, works as a delight.

Cheers
Frenk
 
J

Jean-Guy Marcil

Frenk Nijssen was telling us:
Frenk Nijssen nous racontait que :
Thanks a lot Jean-Guy,

Perfect piece of code, works as a delight.

Cheers
Frenk

Glad to be of service!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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