View Single Post
  #4   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Making users fill in the form in Word

Macropod's macro does have the odd bug, including the use of oFld and aField
to reference the same thing (clearly a typo) but even with that fixed, the
reload function doesn't work as intended.

Take a look at http://www.gmayor.com/formfieldmacros.htm the validation
method shown will not allow you to leave a form field that has not been
filled.

Both methods do, however, require that the user allows any macros saved with
the document to be run, and you cannot rely on that.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



lorican wrote:
thanks for the reply. sadly i'm not very good with advanced word.

I've found 'ThisDocument' module in the 'MicroSoft Objects' folder and
I've copied your marco in to it and clicked on save. To test it, when
I try to close the word document down the macro screen opens up and a
"compile error" message appears. Is that supposed to happen?


'macropod[_2_ Wrote:
;359490']Hi lorican,

If you place the following vba code in the 'ThisDocument' module, it
will prevent the document being closed if it contains any
formfields that have not been filled in.

Private Sub Document_Close()
Dim oFld As FormField
For Each oFld In ActiveDocument.FormFields
If Trim(oFld.Result) = "" Then
MsgBox "Please complete all the items"
ThisDocument.Reload
Exit Sub
End If
Next aField
End Sub

Note: If the user disables macros upon loading the document or their
macro security setting is too high, the code won't work and
they'll be able to close the document without filling in all the
formfields.


--
Cheers
macropod
[MVP - Microsoft Word]

--