G
Gordon
I have created a form template that uses application
events to that check that certain fields are not blank
before the document can be saved. (My thanks to Peter
Hewett and Jezebel from previous posts).
One interesting side-effect of this event catcher is that
each time the document is saved (with or without the
required field filled in), the document scrolls to the top
of the first page. The cursor does not move, just the
document. This happens on both "normal" save (cntrl-S)
and auto saves. It also happends regardless of whether or
not the form is protected.
What can I do to stop this scrolling?
My code is listed below.
Thanks,
Gordon.
''''''''''''''''''''''''''''''
Option Explicit
' Application event logic taken from
'
http://word.mvps.org/FAQs/Customization/ProtectWord2000Plus
HeaderContent.htm
'reserve memory for an application variable
Private WithEvents wdApp As Word.Application
Private Sub Document_New()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub Document_Open()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub wdApp_DocumentBeforeSave(ByVal Doc As
Document, SaveAsUI As Boolean, Cancel As Boolean)
'quit if active doc isn't attached to this template
If Doc.AttachedTemplate <> ThisDocument Then Exit Sub
' Cancel save if Text1 is blank
If Doc.FormFields("Text1").Result = "" _
Then
MsgBox "Please enter Text1 before saving."
Doc.FormFields("Text1").Range.Select
Cancel = True 'Cancel the save
End If
End Sub
events to that check that certain fields are not blank
before the document can be saved. (My thanks to Peter
Hewett and Jezebel from previous posts).
One interesting side-effect of this event catcher is that
each time the document is saved (with or without the
required field filled in), the document scrolls to the top
of the first page. The cursor does not move, just the
document. This happens on both "normal" save (cntrl-S)
and auto saves. It also happends regardless of whether or
not the form is protected.
What can I do to stop this scrolling?
My code is listed below.
Thanks,
Gordon.
''''''''''''''''''''''''''''''
Option Explicit
' Application event logic taken from
'
http://word.mvps.org/FAQs/Customization/ProtectWord2000Plus
HeaderContent.htm
'reserve memory for an application variable
Private WithEvents wdApp As Word.Application
Private Sub Document_New()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub Document_Open()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub wdApp_DocumentBeforeSave(ByVal Doc As
Document, SaveAsUI As Boolean, Cancel As Boolean)
'quit if active doc isn't attached to this template
If Doc.AttachedTemplate <> ThisDocument Then Exit Sub
' Cancel save if Text1 is blank
If Doc.FormFields("Text1").Result = "" _
Then
MsgBox "Please enter Text1 before saving."
Doc.FormFields("Text1").Range.Select
Cancel = True 'Cancel the save
End If
End Sub