Message box on exiting MS Word form help

D

Debbiedo

I have the following code in my MS Word 2003 protected form to display
a message box when saving but how can I modify it to display when
exiting (ie, hitting the X in the corner or Exit from the File menu)?

Public Sub FileSave()

Dim Answer As Integer
Dim Msg As String
On Error Resume Next
Msg = "If Student ID is NOT filled out" & _
vbCr & "click Cancel and go back."
Answer = MsgBox(Msg, vbOKCancel)
If Answer = vbOK Then
ActiveDocument.Save
End If

End Sub

Thanks in advance
 
D

David Sisson

Like this...

Sub Filesave()
Call DisplayMessage
ActiveDocument.Save
End Sub


Sub fileclose()
Call DisplayMessage
ActiveDocument.Close SaveChanges:=wdPromptToSaveChanges
End Sub


Sub fileexit()
Call DisplayMessage
Application.Quit SaveChanges = wdPromptToSaveChanges
End Sub


Sub DisplayMessage()
MsgBox "Is Student's ID filled in?"

End Sub

Of course, this happens EVERYTIME they save, close, or quit, even if
the ID is on place. If you have the student ID in a formfield, then
you could check for it and prompt accordingly.

Sub DisplayMessage()
If Trim(ActiveDocument.FormFields("STUDENTID").Result) <> "" Then
MsgBox "Is Student's ID filled in?"
End If

End Sub


This does not capture the X in the upper right. I beleive this
requires a API call.

Maybe some else can help you with that.
 

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