View Single Post
  #3   Report Post  
lorican lorican is offline
Junior Member
 
Posts: 2
Default

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?


Quote:
Originally Posted by macropod[_2_] View Post
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]

--

Last edited by lorican : August 21st 08 at 08:50 AM