Need help in working a class event handler...

J

joep3

I'm trying to check a formfield on its contents and message box to the user
about no entry and not allow printing. I've found the code that allows
msgboxing from the
AppThatLooksInsideThisEventHandler_DocumentBeforePrint(ByVal Doc As
Document, Cancel As Boolean) routine in the class event handler. Where do I
place the code to check the formfield? I tired to run this code from a class
module within the document itself, which I would rather do, but it doesn't
work. Can I refer to the class module in a document module or do I create a
new class module in the documemt I want to check? Also, I want to cancel the
printing if the contents are not filled in. Can all of this be done in one
document without needing to addin an event handler dot?
 
T

Tony Jollans

You can do this with an application event handler if you want, but an easier
way is simply to trap the print request.

In a standard module create two procedures:

Sub FilePrint
' Traps File > Print from the Menu
End Sub


Sub FilePrintDefault
' Traps pressing on the Print icon on the standard Toolbar
End Sub
 
J

joep3

I tried what you said, but it keeps recursing itself through the printfile
sub. Also, I don't see a way to prevent printing
 
J

joep3

Here is an example that's not working in the module
Public Function text_check() As Boolean
Dim retval
If ActiveDocument.FormFields("Text").Result = "<< ENTER SALUTATION >>"
Or ActiveDocument.FormFields("Text").Result = "" Then
' MsgBox "Formfield has not been filled out... can not exit"
retval = False
Else
retval = True
End If

End Function

Sub FilePrint()
MsgBox "fileprint"
retval = text_check()
End Sub
 
T

Tony Jollans

What exactly do you mean by not working?

The FilePrint routine will run when the user selects File > Print. It runs
*instead of* (not as well as) the built in command. If, having made your
checks, you do want to print, you must do so explicitly.

Public Function text_check() As Boolean
Dim retval
If ActiveDocument.FormFields("Text").Result = "<< ENTER SALUTATION >>"
Or ActiveDocument.FormFields("Text").Result = "" Then
' MsgBox "Formfield has not been filled out... can not exit"
retval = False
Else
retval = True
End If

End Function

Sub FilePrint()
MsgBox "fileprint"
retval = text_check()
'============================
If retval then activedocument.printout ' etc.
'============================
End Sub
 
J

joep3

I was using the eventhandler.dot example that you must set as an addin to the
document or template. I then call the template. It was not working because I
saved the template with the eventhandler as an addin to the 2nd template. I
realize now that the second template did not save the addin. The addin was
there but not checked. When I rechecked it, it worked. I'll try your solution
which is more of what I want. I still don't get the need for creating
instances for your code. Even if you want the code to run in 100 different
documents, I would rather want to find the code inside the document I am
working with...

Thanks for the example!
 
J

joep3

Oh - One more thing , I need to call all the events that a user can choose
from via Word (i.e. save as, print, print preview, save, close, etc...)
 

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