Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Application Events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Bassett - 11 May 2004 18:14 GMT
I am attempting to use the
Application.DocumentBeforePrint event to trigger a
UserForm. I have a class containing the required code to
open the userform on condition that various formfields
have not been filled in, and the class is registered on
opening the document. All works well but only once. If I
launch the print task then the form opens, I then cancel
the print and launch print again but the form doesn't
open, I have to run the registration manually or close
and re-open the document before it will work again. What
can I do to overcome this problem?

Also I would like to know if it is possible to cancel the
print from the event procedure as I do not want the user
to be able to print if the fields are not filled in.
Word Heretic - 13 May 2004 01:51 GMT
G'day "Mike Bassett" <anonymous@discussions.microsoft.com>,

Without code samples, its just pure guesswork. Are you using magic
forms? Don't.

Ie

Bad:

frmUserForm1.show

Good

Dim MyForm as frmUserForm1

Set MyForm = new frmUserForm1
MyForm.Show
Set MyForm=Nothing

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)

Mike Bassett reckoned:

>I am attempting to use the
>Application.DocumentBeforePrint event to trigger a
[quoted text clipped - 11 lines]
>print from the event procedure as I do not want the user
>to be able to print if the fields are not filled in.
Steve Lang - 14 May 2004 00:44 GMT
Hi Mike,

Just a thought, but why use an application event? Hijack the FilePrint
macro. Put your code in and if all is good, display the regular print
dialog. If not, exit the sub and the user cannot print. Using the
application event is probably adding more complexity - and opportunity for
error - than required.

Sub FilePrint
   'your code here
   If isGood Then Dialogs(wdDialogFilePrint).Show
End Sub

HTH and have a great day!

Steve

> I am attempting to use the
> Application.DocumentBeforePrint event to trigger a
[quoted text clipped - 11 lines]
> print from the event procedure as I do not want the user
> to be able to print if the fields are not filled in.
Dana Farmer - 18 Mar 2005 21:52 GMT
I was going to write code for FilePrint but that doesn't take care of the
Print button on the Standard toolbar.  I am now trying to create code for
DocumentBeforePrint so that I can run some code.  I have tried to follow
the Using Events with the Application Object and DocumentBeforePrint Event
help but it is still allowing me to print the document when there should be
errors, it isn't hitting the DocumentBeforePrint event.  Here is the Event
Class Module.

Public WithEvents wApp As Word.Application

Private Sub wApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As
Boolean)
       
   Dim UserResponse As Integer
   
   UserResponse = MsgBox("You need to Save before Print, do you want to
Save now?", vbYesNo)
   
   If UserResponse = vbNo Then
       Cancel = True
   End If
   
   If UserResponse = vbYes Then
          ' vSave is defined in InitializeVariables Macro so it can be
used by multiple Macros / Modules
          Dim Save_Completed As String
       
          ' Final Processing (includes Validation)
          Application.Run "FinalProcessing"
         
          ' Do NOT Create OutLook Task  OR  Save Document
          If vSave = "No" Then
              Cancel = True
              GoTo NoPrint
          End If
         
          ' If no Special Condition entered, fill in "None"
          If ActiveDocument.FormFields("SpclCond").Result = "" Then
              ActiveDocument.FormFields("SpclCond").Result = "None"
          End If
       
          ' Fill in Invoice Information
          Application.Run "FillInvoiceInfo"
         
           ' Save Document
           If Len(ActiveDocument.Path) <> 0 Then          ' Document has
been Saved before
              ActiveDocument.Save
           Else
' Document has NOT been Saved before
             Save_Completed = Dialogs(wdDialogFileSaveAs).Show
              If Save_Completed = False Then
                  Cancel = True
                  GoTo NoPrint
              End If
          End If
        End If      ' Response = Yes (User wants to Save)

NoPrint:

End Sub

I also have the following module:

Sub Register_Event_Handler()
   
   ' Initialize an Instance of the Event Class Module so that Document
Before Print is Executed
   Dim PrintEvent As New EventClassModule
   
   Set PrintEvent.wApp = Word.Application

End Sub

When the document is opened I have a macro that does some initialization
including:
       Application.Run "Register_Event_Handler"

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.