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?
--
Otium Cum Dignatate

Re: Need help in working a class event handler... by Tony

Tony
Wed Apr 26 17:17:31 CDT 2006

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

--
Enjoy,
Tony

"joep3" <joep3@discussions.microsoft.com> wrote in message
news:73B0A789-12A2-4C50-B174-95E349C50856@microsoft.com...
> 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?
> --
> Otium Cum Dignatate



Re: Need help in working a class event handler... by joep3

joep3
Thu Apr 27 09:29:02 CDT 2006

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


"Tony Jollans" wrote:

> 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
>
> --
> Enjoy,
> Tony
>
> "joep3" <joep3@discussions.microsoft.com> wrote in message
> news:73B0A789-12A2-4C50-B174-95E349C50856@microsoft.com...
> > 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?
> > --
> > Otium Cum Dignatate
>
>
>

Re: Need help in working a class event handler... by joep3

joep3
Thu Apr 27 09:31:02 CDT 2006

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


--
Otium Cum Dignatate


"Tony Jollans" wrote:

> 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
>
> --
> Enjoy,
> Tony
>
> "joep3" <joep3@discussions.microsoft.com> wrote in message
> news:73B0A789-12A2-4C50-B174-95E349C50856@microsoft.com...
> > 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?
> > --
> > Otium Cum Dignatate
>
>
>

Re: Need help in working a class event handler... by Tony

Tony
Thu Apr 27 13:18:16 CDT 2006

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



--
Enjoy,
Tony

"joep3" <joep3@discussions.microsoft.com> wrote in message
news:DCA056C1-9110-4E2C-B497-5ECF72D95A2C@microsoft.com...
> 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
>
>
> --
> Otium Cum Dignatate
>
>
> "Tony Jollans" wrote:
>
> > 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
> >
> > --
> > Enjoy,
> > Tony
> >
> > "joep3" <joep3@discussions.microsoft.com> wrote in message
> > news:73B0A789-12A2-4C50-B174-95E349C50856@microsoft.com...
> > > 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?
> > > --
> > > Otium Cum Dignatate
> >
> >
> >



Re: Need help in working a class event handler... by joep3

joep3
Thu Apr 27 13:43:02 CDT 2006

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!
--
Otium Cum Dignatate


"Tony Jollans" wrote:

> 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
>
>
>
> --
> Enjoy,
> Tony
>
> "joep3" <joep3@discussions.microsoft.com> wrote in message
> news:DCA056C1-9110-4E2C-B497-5ECF72D95A2C@microsoft.com...
> > 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
> >
> >
> > --
> > Otium Cum Dignatate
> >
> >
> > "Tony Jollans" wrote:
> >
> > > 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
> > >
> > > --
> > > Enjoy,
> > > Tony
> > >
> > > "joep3" <joep3@discussions.microsoft.com> wrote in message
> > > news:73B0A789-12A2-4C50-B174-95E349C50856@microsoft.com...
> > > > 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?
> > > > --
> > > > Otium Cum Dignatate
> > >
> > >
> > >
>
>
>

Re: Need help in working a class event handler... by joep3

joep3
Thu Apr 27 13:57:01 CDT 2006

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...)
--
Otium Cum Dignatate


"joep3" wrote:

> 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!
> --
> Otium Cum Dignatate
>
>
> "Tony Jollans" wrote:
>
> > 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
> >
> >
> >
> > --
> > Enjoy,
> > Tony
> >
> > "joep3" <joep3@discussions.microsoft.com> wrote in message
> > news:DCA056C1-9110-4E2C-B497-5ECF72D95A2C@microsoft.com...
> > > 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
> > >
> > >
> > > --
> > > Otium Cum Dignatate
> > >
> > >
> > > "Tony Jollans" wrote:
> > >
> > > > 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
> > > >
> > > > --
> > > > Enjoy,
> > > > Tony
> > > >
> > > > "joep3" <joep3@discussions.microsoft.com> wrote in message
> > > > news:73B0A789-12A2-4C50-B174-95E349C50856@microsoft.com...
> > > > > 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?
> > > > > --
> > > > > Otium Cum Dignatate
> > > >
> > > >
> > > >
> >
> >
> >